Fix OCI library linking error by making common library dependencies PUBLIC #45
+823
−101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The build was failing with undefined reference errors for
PullOCIModelandFreeStringsymbols when linking executables that depend on thecommonlibrary:This affected multiple targets including:
llama-parallelllama-batchedllama-lookaheadllama-lookupllama-embeddingllama-eval-callbackRoot Cause
The
commonlibrary is a static library that includesoci.cpp, which calls functions from the Go-based OCI library (liboci.a). The OCI library and other dependencies were linked tocommonwithPRIVATEvisibility:When a static library links to dependencies privately, those dependencies are not propagated to executables that link against it. This meant that while
commonitself could compile with access to the OCI symbols, executables linking tocommondidn't automatically getliboci.a, resulting in undefined references at link time.Solution
Changed the linkage of
LLAMA_COMMON_EXTRA_LIBSfromPRIVATEtoPUBLIC:With
PUBLIClinkage, executables that link to thecommonstatic library now automatically receive all transitive dependencies, including:liboci.a)This is the correct CMake pattern for static libraries with external dependencies.
Testing
nmshows defined symbols)Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
ggml.ai/home/REDACTED/work/llama.cpp/llama.cpp/build/bin/test-arg-parser(dns block)./build/bin/test-arg-parser(dns block)huggingface.co/home/REDACTED/work/llama.cpp/llama.cpp/build/bin/test-thread-safety -hf ggml-org/models -hff tinyllamas/stories15M-q4_0.gguf -ngl 99 -p The meaning of life is -n 128 -c 256 -ub 32 -np 4 -t 2(dns block)/home/REDACTED/work/llama.cpp/llama.cpp/build/bin/llama-eval-callback --hf-repo ggml-org/models --hf-file tinyllamas/stories260K.gguf --model stories260K.gguf --prompt hello --seed 42 -ngl 0(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fix this build:
2025-10-19T16:07:21.2537450Z [ 66%] Linking CXX executable ../../bin/llama-parallel
2025-10-19T16:08:28.9607459Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
nlohmann::json_abi_v3_12_0::detail::parse_error nlohmann::json_abi_v3_12_0::detail::parse_error::create<decltype(nullptr), 0>(int, nlohmann::json_abi_v3_12_0::detail::position_t const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, decltype(nullptr)) [clone .isra.0]': 2025-10-19T16:08:29.0107835Z oci.cpp:(.text+0x1188): undefined reference toPullOCIModel'2025-10-19T16:08:29.0522439Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
oci_pull_model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': 2025-10-19T16:08:29.0926875Z oci.cpp:(.text+0x12e4): undefined reference toFreeString'2025-10-19T16:08:29.2301162Z collect2: error: ld returned 1 exit status
2025-10-19T16:08:29.2645893Z gmake[2]: *** [examples/lookahead/CMakeFiles/llama-lookahead.dir/build.make:106: bin/llama-lookahead] Error 1
2025-10-19T16:08:29.2823311Z gmake[1]: *** [CMakeFiles/Makefile2:1582: examples/lookahead/CMakeFiles/llama-lookahead.dir/all] Error 2
2025-10-19T16:08:29.3001425Z gmake[1]: *** Waiting for unfinished jobs....
2025-10-19T16:08:29.3931059Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
nlohmann::json_abi_v3_12_0::detail::parse_error nlohmann::json_abi_v3_12_0::detail::parse_error::create<decltype(nullptr), 0>(int, nlohmann::json_abi_v3_12_0::detail::position_t const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, decltype(nullptr)) [clone .isra.0]': 2025-10-19T16:08:29.4157193Z oci.cpp:(.text+0x1188): undefined reference toPullOCIModel'2025-10-19T16:08:29.4360871Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
oci_pull_model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': 2025-10-19T16:08:29.4570279Z oci.cpp:(.text+0x12e4): undefined reference toFreeString'2025-10-19T16:08:29.6781309Z collect2: error: ld returned 1 exit status
2025-10-19T16:08:29.6958093Z gmake[2]: *** [examples/batched/CMakeFiles/llama-batched.dir/build.make:106: bin/llama-batched] Error 1
2025-10-19T16:08:29.7141021Z gmake[1]: *** [CMakeFiles/Makefile2:1304: examples/batched/CMakeFiles/llama-batched.dir/all] Error 2
2025-10-19T16:08:29.9080880Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
nlohmann::json_abi_v3_12_0::detail::parse_error nlohmann::json_abi_v3_12_0::detail::parse_error::create<decltype(nullptr), 0>(int, nlohmann::json_abi_v3_12_0::detail::position_t const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, decltype(nullptr)) [clone .isra.0]': 2025-10-19T16:08:29.9300548Z oci.cpp:(.text+0x11fc): undefined reference toPullOCIModel'2025-10-19T16:08:29.9502524Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
oci_pull_model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': 2025-10-19T16:08:29.9713300Z oci.cpp:(.text+0x136c): undefined reference toFreeString'2025-10-19T16:08:30.1858950Z collect2: error: ld returned 1 exit status
2025-10-19T16:08:30.2064968Z gmake[2]: *** [examples/lookup/CMakeFiles/llama-lookup.dir/build.make:106: bin/llama-lookup] Error 1
2025-10-19T16:08:30.2165999Z gmake[1]: *** [CMakeFiles/Makefile2:1619: examples/lookup/CMakeFiles/llama-lookup.dir/all] Error 2
2025-10-19T16:08:30.4263383Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
nlohmann::json_abi_v3_12_0::detail::parse_error nlohmann::json_abi_v3_12_0::detail::parse_error::create<decltype(nullptr), 0>(int, nlohmann::json_abi_v3_12_0::detail::position_t const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, decltype(nullptr)) [clone .isra.0]': 2025-10-19T16:08:30.4428373Z oci.cpp:(.text+0x1188): undefined reference toPullOCIModel'2025-10-19T16:08:30.4591948Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function
oci_pull_model(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': 2025-10-19T16:08:30.4697304Z oci.cpp:(.text+0x12e4): undefined reference toFreeString'2025-10-19T16:08:30.4806423Z /usr/bin/ld: ../../common/libcommon.a(oci.cpp.o): in function `nlohmann::json_abi_v3_12_0::detail::parse_error nlohmann::json_abi_v3_12_0::detail::parse_error::create<decltype(nullptr), 0>(int, nlohmann::json_abi_v3_12_0::detail::position_t const&, std::__cxx11::basic_string<char, std::char_traits, std:...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.