I am trying to compile simple C code on my system. I am running gcc version (4.9.2) on macOS 10.11.6.
ld: library not found for -lgcc
collect2: error: ld returned 1 exit status
I am unable to fix this issue. This problem is not letting me install any ./configure packages as well since they require gcc to work.
Even if there is a program called gcc under macOS, it is not a real gcc compiler. It is just a Clang compiler, as you can prove easily:
gcc --version
will print:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
You should be able to compile and link your program by omitting the -lgcc flag from the command line.
Related
Is there any way to run gcc with the following flags on an apple M1 chip?
gcc -m32 -o test test.c
It outputs the following error:
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You may not run 32-bit applications on macos Catalina or newer. The oldest version of macOS supported on any Apple Silicon (M1/M2) systems is Big Sur, which is the release after Catalina.
So use of -m32 on gcc or any other compiler on macOS is a not supported. Well, I suppose you could use a cross compiler to target a different operating system than the machine you are running the compiler.
Fix:
Remove -m32 and fix any issues with the code.
you can try using an IDE like Xcode or CLion as a workaround while they update GCC.
Since the latest update of Xcode 12 on my recently upgraded MacBook from Mojave to Catalina, I can no longer build my project that uses an old MakeFile. I've tried setting SDKROOT env var and added -isysroot to the old MakeFile but still I get the error:
gcc -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -ggdb -w -DREAL_8 -DINTEGER_IS_INT -DLITTLE_ENDIAN -DTABLE_PATH=\"/usr/lib/\" -c PBGroutines.c
make[1]: *** No rule to make target `/usr/include/stdio.h', needed by `extras.o'. Stop.
I've tried using gcc:
gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
also gcc-10 installed through HomeBrew:
gcc-10 -v
Using built-in specs.
COLLECT_GCC=gcc-10
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/10.2.0/libexec/gcc/x86_64-apple-darwin19/10.2.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/10.2.0 --libdir=/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 10.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SED=/usr/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (Homebrew GCC 10.2.0)
and finally clang:
clang -v
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
but all fail with the same error. I'm running out of ideas after searching extensively.
commandline-tools are installed as noted by xcode-select --install and stdio.h is located in the SDK. What am I missing?
EDIT
Just now noticed that the line before the error refers to PBGroutines.c while the error relates to extras.o. Hence, the problem seems with linking. Also running just the gcc command (with or without) -isysroot runs fine. So how can I do something similar for the linking step?
EDIT 2
So I have found the problem. Apparently this library MakeFile includes the following line:
include make.dep
The content of make.dep contains dependencies with are hardcoded:
#
# Header file dependencies
#
PBGroutines.o: PBGroutines.h
crexrd.o: /usr/include/stdio.h
extras.o: /usr/include/stdio.h
Removing the include make.dep from the MakeFile fixes compilation but I am not sure if this is wanted behaviour? Is it better to create another make.dep with dynamically created file locations? What does this make.dep actually do?
Building my project I get error:
ld: library not found for -lglfw
clang: error: linker command failed with exit code 1 (use -v to see invocation)
But I have installed glfw, via brew install glfw
brew list --versions | grep glfw
glfw 3.2.1
ls /usr/local/lib | grep glfw
libglfw.3.2.dylib
libglfw.3.dylib
libglfw.dylib
clang -v
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
MacOS : 10.14.1 (18B75)
Looks like adding export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib to ~/.bash_profile solved the problem, but I'm not sure if it's ellegant solution without side effects.
I am trying to use --thread-sanitizer option of clang on OSX:
$ clang++ -fthread-sanitizer -fpic tsan1.cc
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
[...]
clang -cc1 version 4.2 based upon LLVM 3.2svn default target x86_64-apple-darwin12.3.0
[...]
Undefined symbols for architecture x86_64:
"___tsan_func_entry", referenced from:
threadfunc(void*) in tsan1-6f7gbr.o
[...]
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Looks like a linkage error. Should I link with some additional libs?
ThreadSanitizer is unsupported on Darwin for C++ yet. This is unlikely to change in at least half a year.
It's been fixed.
According to https://clang.llvm.org/docs/ThreadSanitizer.html
ThreadSanitizer is supported on the following OS:
... Darwin arm64, x86_64, ...
Also I just used it without any problems.
I am trying to compile opencv 2.4.5 with CUDA support in Mac OS X. I am using the cmake gui 2.8.10 with Qt 4.8
After a
clang: error: unsupported option '-dumpspecs'
in the make i have set the entry CUDA_HOST_COMPILER to /usr/bin/llvm-g++ . But now I receive this error:
[ 16%] Built target IlmImf
[ 16%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_matrix_operations.cu.o
cc1plus: warning: command line option "-Wmissing-declarations" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus: error: unrecognized command line option "-Wno-narrowing"
cc1plus: error: unrecognized command line option "-Wno-delete-non-virtual-dtor"
cc1plus: error: unrecognized command line option "-Wno-unnamed-type-template-args"
What can i do now?
SYSTEM SETTINGS
OS X 10.8.3 (12D78)
and
>>> clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
and
>>> g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
>>> ls -al /usr/bin/g++
/usr/bin/g++ -> llvm-g++-4.2
and
>>> cc --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
>>> ls -al /usr/bin/cc
/usr/bin/cc -> clang
Use GCC and G++ to compile. I've used CMake 2.8.11 on OSX Mountain Lion with latest Xcode compilers:
g++ --version returns i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Change the CUDA_HOST_COMPILER from /usr/bin/cc to /usr/bin/gcc
You have to compile the CUDA components using GCC 4.5, while compiling the rest of OpenCV with Clang, otherwise you cannot get the HighGui module to work. HighGui will only compile with the Apple installed compilers because it uses Cocoa. If you do not need HighGui, you can compile OpenCV with GCC. You can specify the proper compilers quite easily with cmake.
I found that the easiest way was to use Homebrew to install cmake and gcc.
I wrote up a detailed gist of how to make it work here that also includes enabling Python support using the Homebrew version.
Disable warning flags in cmake/OpenCVCompilerOptions. Find corresponding warnings and uncomment them using '#'