Saturday, August 12, 2023

[Solved] Fix "ld: library not found for -lc++" errors in macOS


Linker Error:

Run Build Command(s):/usr/local/Cellar/cmake/3.26.3/bin/cmake -E env VERBOSE=1 /usr/local/bin/gmake -f Makefile cmTC_2eb92/fast && /usr/local/bin/gmake  -f CMakeFiles/cmTC_2eb92.dir/build.make CMakeFiles/cmTC_2eb92.dir/build

    gmake[1]: Entering directory '/Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr'

    Building CXX object CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o

    /Library/Developer/CommandLineTools/usr/bin/c++    -MD -MT CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -c /Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr/testCXXCompiler.cxx

    Linking CXX executable cmTC_2eb92

    /usr/local/Cellar/cmake/3.26.3/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2eb92.dir/link.txt --verbose=1

    /Library/Developer/CommandLineTools/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -o cmTC_2eb92 

    ld: library not found for -lc++

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    gmake[1]: *** [CMakeFiles/cmTC_2eb92.dir/build.make:100: cmTC_2eb92] Error 1

    gmake[1]: Leaving directory '/Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr'

    gmake: *** [Makefile:127: cmTC_2eb92/fast] Error 2


Solution:

export CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include/c++/v1:/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include


export LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/lib

This linker error means the build cannot find the C++ standard library it was told to link against. On macOS it usually points to missing or mismatched Command Line Tools, an incomplete Xcode install, or a stale SDK path picked up by CMake.

Reinstalling the Command Line Tools and pointing the build at the active developer directory generally resolves it, after which the failing link step finds libc++ and completes.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.