Skip to content

Commit

Permalink
refs #52: Test and fix MSVC linker error on duplicated symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Jan 29, 2025
1 parent c3a98d8 commit ee72766
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ExternData/Resources/BuildProjects/CMake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ if(EXISTS "${ED_TEST_DIR}")
foreach(TEST ${ED_TESTS})
add_executable(${TEST}
"${ED_TEST_DIR}/${TEST}.cc"
"${ED_TEST_DIR}/Test_Linkage.cc"
"${ED_TEST_DIR}/Test_Linkage.c"
"${ED_TEST_DIR}/Constants.h"
)
target_compile_features(${TEST} PRIVATE cxx_std_17)
Expand Down Expand Up @@ -73,6 +75,8 @@ if(EXISTS "${ED_TEST_DIR}")
)
if(UNIX)
list(APPEND ED_ALL_LIBS m)
elseif(MSVC)
target_link_options(${TEST} PRIVATE "/FORCE:MULTIPLE")
endif()
target_link_libraries(${TEST} PRIVATE ${ED_ALL_LIBS})

Expand Down
4 changes: 2 additions & 2 deletions ExternData/Resources/Include/msvc_compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
extern "C" {
#endif

extern long timezone = 0;
__declspec(selectany) extern long timezone = 0;

#if defined(G_HAS_CONSTRUCTORS)
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(Timezone_initialize)
#endif
G_DEFINE_CONSTRUCTOR(Timezone_initialize)
static void Timezone_initialize(void) {
static inline void Timezone_initialize(void) {
_get_timezone(&timezone);
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions ExternData/Resources/Test/Test_Linkage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Test_Linkage.c
*
* Copyright (C) 2015-2025, Thomas Beutlich
* All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include "../Include/msvc_compatibility.h"
10 changes: 10 additions & 0 deletions ExternData/Resources/Test/Test_Linkage.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Test_Linkage.cc
*
* Copyright (C) 2015-2025, Thomas Beutlich
* All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include "../Include/msvc_compatibility.h"
#include "Constants.h"

0 comments on commit ee72766

Please sign in to comment.