Skip to content

Commit ee72766

Browse files
committed
refs #52: Test and fix MSVC linker error on duplicated symbols
1 parent c3a98d8 commit ee72766

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

ExternData/Resources/BuildProjects/CMake/test.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ if(EXISTS "${ED_TEST_DIR}")
4646
foreach(TEST ${ED_TESTS})
4747
add_executable(${TEST}
4848
"${ED_TEST_DIR}/${TEST}.cc"
49+
"${ED_TEST_DIR}/Test_Linkage.cc"
50+
"${ED_TEST_DIR}/Test_Linkage.c"
4951
"${ED_TEST_DIR}/Constants.h"
5052
)
5153
target_compile_features(${TEST} PRIVATE cxx_std_17)
@@ -73,6 +75,8 @@ if(EXISTS "${ED_TEST_DIR}")
7375
)
7476
if(UNIX)
7577
list(APPEND ED_ALL_LIBS m)
78+
elseif(MSVC)
79+
target_link_options(${TEST} PRIVATE "/FORCE:MULTIPLE")
7680
endif()
7781
target_link_libraries(${TEST} PRIVATE ${ED_ALL_LIBS})
7882

ExternData/Resources/Include/msvc_compatibility.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
extern "C" {
2424
#endif
2525

26-
extern long timezone = 0;
26+
__declspec(selectany) extern long timezone = 0;
2727

2828
#if defined(G_HAS_CONSTRUCTORS)
2929
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
3030
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(Timezone_initialize)
3131
#endif
3232
G_DEFINE_CONSTRUCTOR(Timezone_initialize)
33-
static void Timezone_initialize(void) {
33+
static inline void Timezone_initialize(void) {
3434
_get_timezone(&timezone);
3535
}
3636
#endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Test_Linkage.c
2+
*
3+
* Copyright (C) 2015-2025, Thomas Beutlich
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: BSD-2-Clause
7+
*/
8+
9+
#include "../Include/msvc_compatibility.h"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* Test_Linkage.cc
2+
*
3+
* Copyright (C) 2015-2025, Thomas Beutlich
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: BSD-2-Clause
7+
*/
8+
9+
#include "../Include/msvc_compatibility.h"
10+
#include "Constants.h"

0 commit comments

Comments
 (0)