mpicc - clang: error: no such file or directory: - c

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.

Related

Getting warning "include location '/usr/local/include' is unsafe for cross-compilation" every time I try to compile using `clang -Weverything`

Apologies if this question isn't clear, I'm struggling to even start debugging this issue. I'm on macOS and I'm now getting the following error / warning every time I compile C programs using clang with -Weverything and -Werror flags:
error: include location '/usr/local/include' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]
Initially I thought this was an issue related to my code, but I discovered that this error now occurs with every program I try to compile. I've never had this error before despite always compiling with those flags, and because it now occurs with every program, I suspect it's something that's changed with my compiler or my system. The only thing I can think of that has changed recently was me making a few shared folders with a Lubuntu VM on VirtualBox and updating Xcode.
I can compile the program without the -Weverything flag and it appears to work as expected, but I'd like to address the actual issue to continue using -Weverything. As others have mentioned as well as this thread here, using -Weverything -Werror is excessive in real-life scenarios, however, I'm primarily using it as a learning tool and I want to understand why this issue comes up even for basic programs like helloworld.c (see below).
I've come across a discussion here, but the answer references a configure.ac file that I'm not familiar with and not sure how to use.
Let me know if I can provide any more information to help debug this issue.
As an example, here are the results from cc -Weverything -Werror -v helloworld.c:
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
"/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 -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name helloworld.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.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -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/12.0.0/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 -Weverything -Werror -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 -fdebug-compilation-dir /Users/Projects/helloworld -ferror-limit 19 -fmessage-length 204 -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-10.15.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/mn/v00y5wf55qjf76r4q9rvxq1c0000gn/T/helloworld-89fdc3.o -x c helloworld.c
clang -cc1 version 12.0.0 (clang-1200.0.32.2) default target x86_64-apple-darwin19.6.0
error: include location '/usr/local/include' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]
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/12.0.0/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.
1 error generated.
You have two options to get rid of this warning.
Ignore this warning with the -Wno-poison-system-directories option.
Note that prefixing with -Wno- works for all warnings.
Full command:
cc -Weverything -Wno-poison-system-directories -Werror helloworld.c
Set the logical system root with the -isysroot option.
Full command (if the developer command lines tools are installed):
cc -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Weverything -Werror helloworld.c
Full command (using the SDK from inside Xcode):
cc -isysroot "$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" -Weverything -Werror helloworld.c

Cannot cross-compiling code using clang++

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.

Mac freezes when running compiles c application

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

'stdio.h' File Not Found When Compiling Hello World

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.

How can I compile mysql-connector-c for macOS 10.13.x using C?

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>
...

Resources