virtualsquare / virtualsquare/vde-2

macOS CMake build: malformed `vdehist` linker flags

Open Beginner friendly
#71 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
255
Forks
45
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/lib/CMakeLists.txt at the Darwin-specific options for the vdehist target. Configure and build vdehist on macOS, checking the generated link command and whether the build still resolves the _prompt symbol. Done means the linker no longer treats later flags as an archive path and the macOS build completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.