Edit: added output of $cc -v main.c at the end of this post.
I'm using an old Xcode because my kernel extension will support El Capitan. That works with 8.3 by copying the 10.11 SDK from an older Xcode build.
#include <stdio.h> // 'stdio.h' file not found
int main( int argc, char **argv )
{
printf( "Hello World!\n" );
return 0;
}
$ ls -l /usr/include/stdio.h
-r--r--r-- 1 root wheel 19154 Feb 4 2017 /usr/include/stdio.h
$ ls -l /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h
-r--r--r-- 7 mike staff 19154 Feb 3 2017 /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h
I'm trying to build a userspace command line tool to test my kernel extension.
This is a moderately common problem but none of the solutions I've tried so far have worked. There are lots of reports of it happening in Visual Studio, not just Xcode.
Just now I reinstalled the Command Line Tools. I changed the SDK from "latest macOS" to "macOS 10.12".
The source file is called "main.c" - that is, not "main.cpp".
$ cc -v main.c
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 278.4 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0 -fdebug-compilation-dir /Users/mike/Projects/RCI/trunk/HD1/ButtonTest -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/xc/jc2d96hx25l9ntd2vgnh124m0000gn/T/main-7206a2.o -x c main.c
clang -cc1 version 8.1.0 (clang-802.0.42) default target x86_64-apple-darwin16.7.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out
/var/folders/xc/jc2d96hx25l9ntd2vgnh124m0000gn/T/main-7206a2.o -lSystem
/Applications/Xcode_8.3/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/lib/darwin/libclang_rt.osx.a
I Should Not Drink And Code:
My project had at first just one target, for a kernel extension. Later I added a second target for a command-line tool.
When I created a new source file for my command-line tool that source somehow got added to the kernel extension's target. Changing the tool's header search path settings had no effect on my problem because the source was not in the tool's target.
Kernel Extensions - device drivers - have headers that are only from Kernel.framework, in which there is no stdio.h file.
I'll shut up now.
Related
Command:
I am trying to cross compile a simple C++ program using clang++. I'm using Linaro gcc tool-chain to obtain the library and other includes required.
${root}/bin/clang++ --target=arm-linux-gnueabihf --rtlib=compiler-rt --stdlib=libc++ -nostdinc++ -I${root}/include/c++/v1 -Wl,-L${root}/lib --sysroot ${sysroot} --gcc-toolchain=/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf -rpath ${root}/lib TestCodeX86toARM.cpp -o Test -v
The value of root and sysroot is as follows:
root=/path/to/clang/install_dir
sysroot=/path/to/linarogcc/arm-linux-gnueabihf/libc
TestCodeX86toARM.cpp is just a hello world code
output:
clang version 10.0.0
Target: arm-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin
Found candidate GCC installation: /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0
Selected GCC installation: /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0
Candidate multilib: .;#m32
Selected multilib: .;#m32
"/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-10" -cc1 -triple armv6kz-unknown-linux-gnueabihf -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name TestCodeX86toARM.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -target-cpu arm1176jzf-s -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi hard -fallow-half-arguments-and-returns -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -v -nostdinc++ -resource-dir /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/10.0.0 -I /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/include/c++/v1 -isysroot /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc -internal-isystem /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/local/include -internal-isystem /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/10.0.0/include -internal-externc-isystem /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/include -internal-externc-isystem /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include -fdeprecated-macro -fdebug-compilation-dir /home/user/Tejas/CrossCopileTestCode -ferror-limit 19 -fmessage-length 0 -fno-signed-char -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o /tmp/TestCodeX86toARM-438a38.o -x c++ TestCodeX86toARM.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/local/include"
ignoring nonexistent directory "/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/include"
#include "..." search starts here:
#include <...> search starts here:
/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/include/c++/v1
/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/10.0.0/include
/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include
End of search list.
"/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld" --sysroot=/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc -EL -z relro -X --hash-style=gnu --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o Test /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib/crt1.o /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib/crti.o /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/crtbegin.o -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0 -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/lib/../lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/../lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib -L/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib -rpath /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib /tmp/TestCodeX86toARM-438a38.o -lc++ -lm /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/10.0.0/lib/linux/libclang_rt.builtins-armhf.a -lc /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/10.0.0/lib/linux/libclang_rt.builtins-armhf.a /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/crtend.o /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib/crtn.o
/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/libc++.so.1: file not recognized: File format not recognized
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
Your linker is trying to link against libc++. However clang cant find this library in your arm tool-chain ( probably your arm tool-chain is providing libstdc++). So the only libc++ found by the linker is /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/libc++.so.1 which is probably an x86 library ( you can confirm that with objdump or readelf).
Try to replace --stdlib=libc++ by --stdlib=libstdc++ in your command line.
For a long time I have been trying to compile and run c programs on my MacBook Pro running macOS Catalina, I’ve tried compiling with cc, gcc and clang and the compilation seems to work just fine but every time I run the .out file my Mac freezes, I can’t control+c out of the application and even if I terminate the terminal the issue continues with the finder app (it completely stops responding), so in order to fix the problem I have to completely shut the computer off and then turn it on again via the power button.
This issue happens with every program that I have tried, including the “hello, world” program.
I have compiled a minimal test with gcc -v -o demo demo.c and the output is:
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name demo.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.4 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-objc-signed-char-bool-implicit-int-conversion -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdebug-compilation-dir /Users/user -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 -fobjc-runtime=macosx-10.15.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/xj/rw_jny791d9c83w_rplgscnw0000gn/T/demo-635cdc.o -x c demo.c
clang -cc1 version 11.0.3 (clang-1103.0.32.62) default target x86_64-apple-darwin19.4.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 10.15.0 10.15.4 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o demo /var/folders/xj/rw_jny791d9c83w_rplgscnw0000gn/T/demo-635cdc.o -L/usr/local/lib -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/lib/darwin/libclang_rt.osx.a
The solution was to run this command:
export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/
For anyone else that experiences this issue, please see discussion at: Can't compile a C program on a Mac after upgrading to Catalina 10.15
Install LLVM brew install llvm
Edit .zshrc
...
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
...
Create hello.c
#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}
Now, when i run clang -v hello.c, I get:
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
"/usr/local/Cellar/llvm/8.0.1/bin/clang-8" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 450.3 -v -resource-dir /usr/local/Cellar/llvm/8.0.1/lib/clang/8.0.1 -fdebug-compilation-dir /Users/jdriwer/Projects -ferror-limit 19 -fmessage-length 212 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/qg/47c_70qn4wd9tlp18280f7k00000gn/T/hello-4a50cb.o -x c hello.c
clang -cc1 version 8.0.1 based upon LLVM 8.0.1 default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/Cellar/llvm/8.0.1/lib/clang/8.0.1/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
PS. llvm's stdio.h location: /usr/local/Cellar/llvm/8.0.1/include/c++/v1/stdio.h
and /usr/local/opt/llvm ⇒ ../Cellar/llvm/8.0.1 is symbolic link
What's the trouble?
If using an external LLVM installation, add these to your ~/.bash_profile
LLVM_PATH="/usr/local/opt/llvm/" # or any other path
LLVM_VERSION="11.0.0"
export PATH="$LLVM_PATH:$PATH"
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export LD_LIBRARY_PATH="$LLVM_PATH/lib/:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="$LLVM_PATH/lib/:$DYLD_LIBRARY_PATH"
export CPATH="$LLVM_PATH/lib/clang/$LLVM_VERSION/include/"
export LDFLAGS="-L$LLVM_PATH/lib"
export CPPFLAGS="-I$LLVM_PATH/include"
export CC="$LLVM_PATH/bin/clang"
export CXX="$LLVM_PATH/bin/clang++"
(adjust the clang version and the external llvm installation path.)
Then run source ~/.bash_profile
Because ignoring nonexistent directory "/usr/include"
You should install macOS SDK headers from /Library/Developer/CommandLineTools/Packages/
Month ago I installed Open MPI 4.0.1 on macOS Mojave following this Stack Overflow answer.
Back then everything worked and I managed to compile and run hello.c and few other programs.
But when I tried today to compile any program using $HOME/opt/usr/local/bin/mpicc -o program_name ./program_name.c I get error clang: error: no such file or directory: './program_name.c', even though these files are in that directory.
It doesn't even work for hello.c.
But when I try to run existing programs, for example hello, using $HOME/opt/usr/local/bin/mpirun -np 4 hello, it works.
So I don't understand how can I get error no such file or directory if mpi can find and run existing programs, but can't compile files that are in the same directory.
I also tried to position in that directory using cd $HOME/opt/usr/local/bin and then execute mpicc -o hello ./hello.c, but then I get error -bash: mpicc: command not found.
Does anyone know where is the problem and how to solve it?
In case of issues like this, it's good to run mpicc with option -v. This way, you can take a look at all the commands that are executed behind your back
> mpicc -v -o main ./main.c
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -I ... -fdebug-compilation-dir /Users/... -ferror-limit 19 -fmessage-length 173 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/cx/76hd7pcs41g_vdj4qjfx0d4h0000gn/T/main-29e74d.o -x c ./main.c
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.7.0
...
...
This way, you can spot issues related to compiler. Also, make sure your Toolchain hasn't changed after system/XCode upgrade. If you have compiled MPI from sources, it might be you have some discrepancies between what was used during compilation time and what you have now.
Synopsis
I have a small c program, it's a standard "hello world" application to test I can access the mysql connection driver accordingly:
#include <stdio.h>
#include "mysql.h"
int main(int argc, const char **argv)
{
printf("MySQL client version: %s\n", mysql_get_client_info());
return 0;
}
When I compile this using the following; I get an error:
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-o bin/test
Undefined symbols for architecture x86_64:
"_mysql_get_client_info", referenced from:
_main in main-59d4fb.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have then attempted to link mysql with the following:
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-Llib/mysql-connector-c-6.1.11-macos10.12-x86_64/mysql-connector-c-6.1.11-src/libmysql \
-lmysql \
-o bin/test
ld: library not found for -lmysql
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It's worth noting I am using c not c++ and I am not using XCode just Vim and gcc as can be seen above.
Alternative attempt
I then decided perhaps i've done something wrong with compiling the source from MySQL This particular link and so I deleted the lib directory within my application and installed them via homebrew:
I tried brew install mysql-connector-c I also received the same errors as above despite changing the -I -L -l accordingly the new paths /usr/local/Cellar/... and exactly the same problems were occurring.
Conclusion
I could not find any .c files in any of the compiled mysql libraries, I did find a libmysql inside the source i compiled and attempted to link that which also failed. I personally feel it's a linking problem I just don't know what or how, if anyone could help me with this I would really appreciate it.
Anyone who may want to see the response of -v please see below:
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I lib/mysql-connector-c-6.1.11-macos10.12-x86_64/include -I/usr/local/include -Wall -fdebug-compilation-dir /Users/ash/Projects/samp-db2 -ferror-limit 19 -fmessage-length 173 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/v7/_rm0d0qx2r32ln2f7_dpnrw40000gn/T/main-3d5e25.o -x c src/main.c
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.3.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
lib/mysql-connector-c-6.1.11-macos10.12-x86_64/include
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.13.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -o bin/cmig /var/folders/v7/_rm0d0qx2r32ln2f7_dpnrw40000gn/T/main-3d5e25.o -L/usr/local/lib -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
> brew install mysql-connector-c
> clang mysql_connect_test.c -l mysqlclient -o mysql_test
> ./mysql_test
MySQL client version: 6.1.11
same code in mysql_connect_test.c, everything is ok.
> ls /usr/local/Cellar/mysql-connector-c/6.1.11/lib
libmysqlclient.18.dylib libmysqlclient.a libmysqlclient.dylib
Your code just need link to libmysqlclient.
And in your post:
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-o bin/test
It is wrong, because you just pass library search path to gcc, but also need pass which library you should link, for example, -lmysqlclient.
gcc src/main.c \
-Wall \
-Ilib/mysql-connector-c-6.1.11-macos10.12-x86_64/include \
-Llib/mysql-connector-c-6.1.11-macos10.12-x86_64/mysql-connector-c-6.1.11-src/libmysql \
-lmysql \
-o bin/test
wrong name of link library, and mysql-connector-c-6.1.11-macos10.12-x86_64 just contains source code? If yes, you need compile mysql-connector-c first.
my two cents for Catalina:
Use of external C++ headers in Objective-C
it works, using mysql lib version 21.
NO NEED to use brew or similar..
note:
As that lib is not signed. Simply in Entitlemens:
(in XML): ..
<dict>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
...