Skip to content

Fix cmake build: use target_link_libraries instead of LINK_FLAGS - #1

Open
rljacobuc wants to merge 2 commits into
mainfrom
fix/cmake-link-order
Open

Fix cmake build: use target_link_libraries instead of LINK_FLAGS#1
rljacobuc wants to merge 2 commits into
mainfrom
fix/cmake-link-order

Conversation

@rljacobuc

Copy link
Copy Markdown
Owner

Problem

The cmake build failed with hundreds of undefined references to wxWidgets and NetCDF symbols during linking. The root cause is that LINK_FLAGS in set_target_properties places library flags before the object files in the linker command. GNU ld processes flags left-to-right, so libraries listed before the object files that reference them have no unresolved symbols to satisfy and their symbols are discarded, causing the undefined reference errors.

Fix

Replace LINK_FLAGS with the proper cmake mechanisms:

  • target_link_options for the rpath linker flag
  • target_link_libraries for wxWidgets and NetCDF library flags

This ensures libraries appear after the object files in the final linker invocation, as required by GNU ld.

The build.sh script (which invokes g++ directly with libraries after sources) already worked correctly and continues to work.

This PR was generated with Oz.

rljacobuc and others added 2 commits March 5, 2026 22:55
LINK_FLAGS places library flags before object files in the linker
command, causing undefined reference errors with GNU ld which requires
libraries to appear after the object files that use them.

Replace LINK_FLAGS with target_link_options (for rpath) and
target_link_libraries (for wxWidgets and NetCDF libraries) so
that the link order is correct.

Co-Authored-By: Oz <oz-agent@warp.dev>
- Use BUILD_RPATH/INSTALL_RPATH properties instead of raw -Wl,-rpath flag
- Use target_link_directories instead of -L flag in separate_arguments
- Split link items into libraries (target_link_libraries) and flags (target_link_options)
- Use NATIVE_COMMAND instead of UNIX_COMMAND in separate_arguments

Co-Authored-By: Oz <oz-agent@warp.dev>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread src/CMakeLists.txt
Comment on lines +41 to +44
# Link libraries after object files (required for GNU ld)
separate_arguments(WX_LINK_ITEMS NATIVE_COMMAND "${WX_LINK_FLAGS}")
separate_arguments(NC_LINK_ITEMS NATIVE_COMMAND "-lnetcdf ${NC_LINK_FLAGS}")
target_link_directories(ncvis PRIVATE ${NC_LIB_DIR})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Build configuration fails on older CMake versions the project still claims to support

The build script now uses two configuration commands (target_link_directories/target_link_options at src/CMakeLists.txt:44 and src/CMakeLists.txt:72) that only exist in newer CMake, while the project still declares support for a much older minimum version, so configuring the build stops with an error for anyone on an older CMake.
Impact: Users with an older but supposedly supported CMake can no longer configure or build the program at all.

Version requirements of the newly introduced CMake commands

The top-level CMakeLists.txt:1 declares cmake_minimum_required(VERSION 3.1). The new code requires:

  • target_link_directories — CMake 3.13+
  • target_link_options — CMake 3.13+
  • separate_arguments(... NATIVE_COMMAND ...) — CMake 3.9+
  • BUILD_RPATH target property — CMake 3.8+

With CMake < 3.13 the configure step aborts with "Unknown CMake command "target_link_directories"". The minimum required version should be bumped to at least 3.13 (and INSTALL.md build instructions updated if it mentions a version).

Prompt for agents
src/CMakeLists.txt now uses target_link_directories and target_link_options (CMake 3.13+), separate_arguments(NATIVE_COMMAND) (3.9+) and the BUILD_RPATH property (3.8+), but the top-level CMakeLists.txt still says cmake_minimum_required(VERSION 3.1). Configuration will fail with 'Unknown CMake command' on older CMake. Raise the declared minimum required version to match what the new commands need, and check whether INSTALL.md documents a CMake version that should be updated too.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant