Summary
The CMake build on macOS can fail while linking libvdehist.dylib because the Darwin-specific linker options in src/lib/CMakeLists.txt include -Wl,-force_load without the archive path that Darwin ld expects after that option.
The relevant stanza is:
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_compile_options(vdehist PRIVATE -Wall -O2 -g -O2 -fno-common -DPIC)
target_link_options(vdehist PRIVATE -Wl,-undefined -Wl,dynamic_lookup -Wl,-no_fixup_chains -Wl,-force_load -O2 -g -O2)
endif()
Because -force_load consumes the next argument as an archive path, later linker flags can be misinterpreted. In a MacPorts build, this produced:
ld: library '-headerpad_max_install_names' not found
clang: error: linker command failed with exit code 1
Suggested fix
The build appears to still need -undefined dynamic_lookup, because libvdehist.dylib otherwise has an unresolved _prompt symbol on macOS. However, the other hard-coded Darwin flags do not appear to be needed and can interfere with packaging/build-system flags.
This reduced Darwin-specific option worked:
--- src/lib/CMakeLists.txt.orig
+++ src/lib/CMakeLists.txt
@@ -21,10 +21,9 @@ install(TARGETS vdesnmp
add_library(vdehist SHARED libvdehist.c)
target_link_libraries(vdehist PRIVATE vdecommon)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- target_compile_options(vdehist PRIVATE -Wall -O2 -g -O2 -fno-common -DPIC)
- target_link_options(vdehist PRIVATE -Wl,-undefined -Wl,dynamic_lookup -Wl,-no_fixup_chains -Wl,-force_load -O2 -g -O2)
+ target_link_options(vdehist PRIVATE -Wl,-undefined,dynamic_lookup)
endif()
set_target_properties(vdehist PROPERTIES VERSION 0.0.1 SOVERSION 0)
configure_file(vdehist.pc.in ${CMAKE_CURRENT_BINARY_DIR}/vdehist.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vdehist.pc
This lets the build environment provide normal optimization, debug, PIC, SDK, deployment-target, and install-name flags, while preserving the Darwin unresolved-symbol behavior needed by vdehist.
Summary
The CMake build on macOS can fail while linking
libvdehist.dylibbecause the Darwin-specific linker options insrc/lib/CMakeLists.txtinclude-Wl,-force_loadwithout the archive path that Darwinldexpects after that option.The relevant stanza is:
Because
-force_loadconsumes the next argument as an archive path, later linker flags can be misinterpreted. In a MacPorts build, this produced:Suggested fix
The build appears to still need
-undefined dynamic_lookup, becauselibvdehist.dylibotherwise has an unresolved_promptsymbol on macOS. However, the other hard-coded Darwin flags do not appear to be needed and can interfere with packaging/build-system flags.This reduced Darwin-specific option worked:
This lets the build environment provide normal optimization, debug, PIC, SDK, deployment-target, and install-name flags, while preserving the Darwin unresolved-symbol behavior needed by
vdehist.