Clang linking error MacOS Big Sur

Hi All,

I am trying to build my helloworld.cpp, but I am having problem since I updated to Big Sur. Below a verbose screenshot of my build error message. Looks like it cannot link the c++ std library?

I have already tried to remove the command line tool and re install it. No luck.

Code Block
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
ignoring nonexistent directory "/usr/include/c/v1"
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name helloworld.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 609.6 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0 -stdlib=libc -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c/v1 -internal-isystem /usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include -internal-externc-isystem /usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -std=c17 -fdeprecated-macro -fdebug-compilation-dir /Users/***/Documents/CppProject -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/4t/my76lgkd0f7c34tybwg9f6km0000gn/T/helloworld-f9d8e9.o -x c /Users/***/Documents/CppProject/helloworld/helloworld.cpp
clang -cc1 version 12.0.0 (clang-1200.0.32.27) default target x86_64-apple-darwin20.1.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/Library/Developer/CommandLineTools/usr/bin/../include/c/v1
/usr/local/include
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
/Library/Developer/CommandLineTools/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 11.0.0 0.0.0 -o /Users/***/Documents/CppProject/helloworld/helloworld /var/folders/4t/my76lgkd0f7c34tybwg9f6km0000gn/T/helloworld-f9d8e9.o -lc -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a
ld: library not found for -lc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process "/bin/bash '-c', 'clang -std=c17 -stdlib=libc++ -g -v /Users/***/Documents/CppProject/helloworld/helloworld.cpp -o /Users/***/Documents/CppProject/helloworld/helloworld'" terminated with exit code: 1.

Nearly the same problem. In my case it says that /usr/lib/libstdc is not found, but I suppose it should use libc
Similar problem here: ld: library not found for -lSystem

It seems like there is no GCC support in Big Sur (?)




Similar problem here: ld: library not found for -lSystem
It seems like there is no GCC support in Big Sur (?)

I get the same message when I try to build with GCC as well.
I have the same Problem with clang. If I specify the library path in the developer tools with:

clang helloworld.cpp -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

it compiles fine.
However I need clang to search this path by itself since it is called from another program.
Adding the path or exporting it as DYLNLIBRARYPATH didn't work.
Does anyone know how to do this?
Hi! Does anyone know how to solve this? Reinstalling command line tools didn't help me.

I get the error when I try to use clang from llvm formula from brew in my CMake project.

Code Block
ld: library not found for -lSystem
clang-11: error: linker command failed with exit code 1


I get the error when I try to use clang from llvm formula from brew in my CMake project.

What do the developers of brew and CMake say about this problem?




I have the same issue. I am not able to compile using g++. Any solutions?
anything new ? :/
I'm using Geany, for me it solved.
Any luck with this problem? I have a similar error.

Code Block
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)


I am using LDLIBRARYPATH as below in my make file configuration.

Code Block
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib

Hi, I had the same issue ld: library not found for -lSystem and now I have ld: library not found for -lpthread. Reinstalled Command Line tools, removed llvm from brew still not working.

Does anyone have any idea how to fix this?

Thanks
I believe it is this: in Big Sur system dynamic link libraries are not available as separate entities. They're pre-loaded. The -l switch for Apple clang still finds them without a -L switch. Gcc does not. There's no solution for Apple libraries. For C++ standard libraries, you have to install the libraries, they should come with g++ compiler if you're installing using brew.

I guess the reasons: Faster loading, faster access, less VM manager resource use, and last but not least, vastly improved security (it stops hijacking).

As suggested by @NavyOwl in the response, adding the following compilation flag fixes the problem:

Code Block
g++ ... -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

In order to make or cmake compile with this flag, one can define an environment variable (e.g., set in your IDE / bash):

Code Block bash
LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

If you are working from command line:

Code Block bash
export LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
make # or cmake .


If you’re curious as to the backstory here, see this post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

xcode-select --print-path

You may need to change this to your Xcode installation if you separately installed the command line tools and that is the issue:

xcode-select -switch /Applications/Xcode.app

Try also building with clang++ instead of clang. This was causing a linking issue for me.

Clang linking error MacOS Big Sur
 
 
Q