Fix CMake linking order for dlopen/dlsym symbols#252
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a CMake linking order issue that caused Debian 11 build failures with undefined references to dlopen, dlclose, dlsym, and dlerror symbols. The fix moves CMAKE_DL_LIBS (which contains -ldl, -lm, and -lpthread) to appear after the static libraries in the linker command, ensuring that symbols are defined after they are referenced by the static libraries.
Changes:
- Moved
CMAKE_DL_LIBSplacement intarget_link_libraries()calls from before to after thesems_coreandsems_sipstatic libraries - Applied fix consistently to both macOS (
-force_load) and Linux (--whole-archive) build configurations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 3 commits
February 6, 2026 09:30
Replace `git clone --branch master` with `COPY . /sems` in all Debian Dockerfiles, matching the pattern already used by the RHEL Dockerfiles. The git clone approach meant Debian CI builds always tested master, never the actual PR branch code. This made it impossible to test CMake or build system changes before merging.
The CMake migration (6a8e364) removed all Makefiles but left the bullseye and trixie rules files still calling $(MAKE) -C core/ install and $(MAKE) -C apps/ install, which fail with "No rule to make target". Update both to use dh --buildsystem=cmake with proper CMake configure options, matching the pattern already working in bookworm/rules. Codec options are set based on each distro's available dev packages.
The getarch and getos compat binaries are no longer built by CMake. Comment out the compat lines in libsems1-dev.install, matching the pattern already used in bookworm's .install file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CMAKE_DL_LIBS(-ldl) after the static libraries in the link command--whole-archive, the GNU linker processes libraries in order - symbols must be defined after they are referenceddlopen,dlclose,dlsym,dlerrorRoot Cause
The link command was:
The linker saw
-ldlfirst but didn't know it was needed yet. When it processedsems_core(which usesdlopenetc.), the symbols were not available.Fix
Now
-ldlcomes after the static libraries that reference it.Test plan
🤖 Generated with Claude Code