Skip to content

macOS CMake build: malformed vdehist linker flags #71

@pmetzger

Description

@pmetzger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions