OS X: ld: library not found for -lstdc++
Asked Answered
A

2

7

I'm trying to wrap a Python lib around a C++ lib and distutils is failing for me on OS X. Here are the relevant lines from my setup.py:

if sys.platform.startswith("darwin"):
    extra_compile_args_setting = ["-std=c++1z", "-stdlib=libc++", "-O3"]

Here's the relevant output:

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/x/anaconda/include -arch x86_64 -I/Users/x/anaconda/include -arch x86_64 -I../../cpp_client/libsrc -I../../cpp_client/third_party -I/Users/x/anaconda/include/python3.6m -c navdb_python_client_wrap.cxx -o build/temp.macosx-10.7-x86_64-3.6/navdb_python_client_wrap.o -std=c++1z -stdlib=libc++ -O3
clang++ -bundle -undefined dynamic_lookup -L/Users/x/anaconda/lib -L/Users/x/anaconda/lib -arch x86_64 build/temp.macosx-10.7-x86_64-3.6/navdb_python_client_wrap.o -L../../cpp_client/lib -L/Users/x/anaconda/lib -lnavdb_cpp_client_api -o /Users/x/Development/NavDB/trunk/src/client/lang_clients/python3_client/build/_navdb_python_client.cpython-36m-darwin.so
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
ld: library not found for -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang++' failed with exit status 1

I recently upgraded to XCode 10. The library seems to be there:

$ ls -lrt /usr/lib/libstdc++*
lrwxr-xr-x  1 root  wheel       17 Sep 26  2017 /usr/lib/libstdc++.dylib -> libstdc++.6.dylib
lrwxr-xr-x  1 root  wheel       21 Sep 26  2017 /usr/lib/libstdc++.6.dylib -> libstdc++.6.0.9.dylib
-rwxr-xr-x  1 root  wheel  1461584 Mar 28 06:02 /usr/lib/libstdc++.6.0.9.dylib

Any help is welcome.

Ancestral answered 21/9, 2018 at 10:41 Comment(1)
Did you try this: #53288475Cerveny
A
1

Without uninstalling XCode Command Line Tools v10, I installed XCode Command Line Tools v9.4.1 and it fixed the problem.

Ancestral answered 21/9, 2018 at 14:51 Comment(2)
Just running xcode-select --install was enough to fix this for me.Vomitory
XCode 10.1 (with its command line tools) fixes it again, that's likely why running xcode-select --install works again. I think the problem was in 10.0 only.Ancestral
S
0

I had a similar issue here in 2024 on my MacOS 12.7.3 Monterey with my linker failing and reporting

ld: library not found for -lSystem

I had to manually reinstall my command line tools by using

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

which took about 20 minutes but did fix my linker issue.

Southwards answered 26/2 at 20:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.