Skip to content

Commit 4514e02

Browse files
author
marcel
committed
Fix CMake linking order for dlopen/dlsym symbols
Move CMAKE_DL_LIBS (-ldl) after the static libraries (sems_core, sems_sip) in the link command. With --whole-archive, the GNU linker processes libraries in order and needs to see the libraries that define symbols after the objects that reference them. This fixes the Debian 11 build failure where linking failed with undefined references to dlopen, dlclose, dlsym, and dlerror from libsems_core.a.
1 parent fc43a58 commit 4514e02

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ foreach(EXE_TARGET sems sems_tests)
3434
if(APPLE)
3535
target_link_libraries(
3636
${EXE_TARGET}
37-
${CMAKE_DL_LIBS}
3837
-Wl,-force_load
3938
sems_core
4039
-Wl,-force_load
4140
sems_sip
41+
${CMAKE_DL_LIBS}
4242
event
4343
event_pthreads
4444
-rdynamic)
4545
else()
4646
target_link_libraries(
4747
${EXE_TARGET}
48-
${CMAKE_DL_LIBS}
4948
-Wl,--whole-archive
5049
sems_core
5150
sems_sip
5251
-Wl,--no-whole-archive
52+
${CMAKE_DL_LIBS}
5353
event
5454
event_pthreads
5555
-rdynamic)

0 commit comments

Comments
 (0)