Skip to content

Fix macOS linker error: replace pkg-config JsonCpp detection with CMake target linking#109

Merged
dfeen87 merged 2 commits into
mainfrom
copilot/fix-cmake-jsoncpp-link-error
Feb 22, 2026
Merged

Fix macOS linker error: replace pkg-config JsonCpp detection with CMake target linking#109
dfeen87 merged 2 commits into
mainfrom
copilot/fix-cmake-jsoncpp-link-error

Conversation

Copilot AI commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

On Apple Silicon macOS, pkg_check_modules(JSONCPP jsoncpp) resolves JSONCPP_LIBRARIES to the raw flag -ljsoncpp, which the macOS linker cannot resolve. Homebrew-installed JsonCpp exposes a proper CMake config package with the jsoncpp_lib target.

Changes

  • JsonCpp detection — replace the pkg_check_modules + find_package fallback chain with a single find_package(jsoncpp CONFIG QUIET)
  • Linking — remove ${JSONCPP_LIBRARIES} from both ailee_node and ailee_adapters; link via jsoncpp_lib target inside a if(jsoncpp_FOUND) guard instead
  • Include dirs — remove ${JSONCPP_INCLUDE_DIRS} from global include_directories; the jsoncpp_lib target propagates its own includes transitively
  • Compile definitions — consolidate AILEE_HAS_JSONCPP=1 into the same if(jsoncpp_FOUND) block, removing the now-redundant if(JSONCPP_FOUND OR jsoncpp_FOUND) checks

Before:

pkg_check_modules(JSONCPP jsoncpp)          # sets JSONCPP_LIBRARIES = -ljsoncpp on macOS
if(NOT JSONCPP_FOUND)
    find_package(jsoncpp QUIET)
    ...
endif()
# later:
target_link_libraries(ailee_node PRIVATE ... ${JSONCPP_LIBRARIES} ...)  # ld: library 'jsoncpp' not found

After:

find_package(jsoncpp CONFIG QUIET)
# later:
if(jsoncpp_FOUND)
    target_link_libraries(ailee_node PRIVATE jsoncpp_lib)
    target_compile_definitions(ailee_node PRIVATE AILEE_HAS_JSONCPP=1)
endif()

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ONFIG QUIET)

Co-authored-by: dfeen87 <158860247+dfeen87@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix macOS linker error for JsonCpp in CMakeLists.txt Fix macOS linker error: replace pkg-config JsonCpp detection with CMake target linking Feb 22, 2026
Copilot AI requested a review from dfeen87 February 22, 2026 01:02
@dfeen87 dfeen87 marked this pull request as ready for review February 22, 2026 01:02
Copilot AI review requested due to automatic review settings February 22, 2026 01:02
@dfeen87 dfeen87 merged commit 1876bb5 into main Feb 22, 2026
2 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI 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.

Pull request overview

This PR fixes a macOS linker error where pkg-config resolves JsonCpp to an unresolvable -ljsoncpp flag. The solution replaces the pkg-config detection with CMake's config-based package discovery, which provides proper imported targets with transitive include and link dependencies.

Changes:

  • Simplified JsonCpp detection to use find_package(jsoncpp CONFIG QUIET) instead of a pkg-config + fallback chain
  • Replaced raw library flag linking (${JSONCPP_LIBRARIES}) with CMake target linking (jsoncpp_lib) for both ailee_node and ailee_adapters
  • Consolidated compile definitions and linking into single conditional blocks guarded by jsoncpp_FOUND

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dfeen87 dfeen87 deleted the copilot/fix-cmake-jsoncpp-link-error branch April 5, 2026 18:46
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.

3 participants