Using makefile with pybind11 - c++

I am trying to manually compile a c++ project that uses pybind11. I am able to make it work but I don't understand one compilation problem.
Here is a minimal example: I have a folder containing the makefile and folders lib/, bin/ and src/. src/ contains the following files implementing a function that is just returns 1.
src/hi.hpp
#ifndef hi_hpp
#define hi_hpp
#include <stdio.h>
int get1();
#endif
src/hi.cpp
#include "hi.hpp"
int get1() {
return 1;
}
src/bind_hi.cpp
#include "hi.hpp"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
namespace py = pybind11;
PYBIND11_MODULE( hi, m ) {
m.doc() = "doc"; // optional module docstring
m.def("get1", &get1, "get 1");
}
makefile (working)
CXX:=clang++
CXXFLAGS:=-Ofast -Wall -shared -std=c++11 -undefined dynamic_lookup -fPIC -I/Users/user/opt/anaconda3/include/python3.8 -I/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I/src
EXT:=$(shell python3-config --extension-suffix)
DEPS:= src/hi.cpp src/bind_hi.cpp
hi.$(EXT): $(DEPS)
$(CXX) $(CXXFLAGS) $(DEPS) -o lib/hi$(EXT) -v
clean:
#rm lib/*$(EXT)
.PHONY=clean
Here is the output I get during compilation:
clang++ -Ofast -Wall -shared -std=c++11 -undefined dynamic_lookup -fPIC -I/Users/user/opt/anaconda3/include/python3.8 -I/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I/src src/hi.cpp src/bind_hi.cpp -o lib/hi.cpython-38-darwin.so -v
clang version 10.0.0
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Users/user/opt/anaconda3/bin
"/Users/user/opt/anaconda3/bin/clang-10" -cc1 -triple x86_64-apple-macosx10.16.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hi.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 241.9 -v -resource-dir /Users/user/opt/anaconda3/lib/clang/10.0.0 -I /Users/user/opt/anaconda3/include/python3.8 -I /Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I /src -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -stdlib=libc++ -internal-isystem /Users/user/opt/anaconda3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Users/user/opt/anaconda3/lib/clang/10.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -Ofast -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/user/Documents/python_package_example -ferror-limit 19 -fmessage-length 158 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.16.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/xy/lcpszqt54bg9_4xnrhdk9j500000gp/T/hi-ffd9cb.o -x c++ src/hi.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include"
ignoring nonexistent directory "/src"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
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:
/Users/user/opt/anaconda3/include/python3.8
/Users/user/opt/anaconda3/bin/../include/c++/v1
/Users/user/opt/anaconda3/lib/clang/10.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Users/user/opt/anaconda3/bin/clang-10" -cc1 -triple x86_64-apple-macosx10.16.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name bind_hi.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 241.9 -v -resource-dir /Users/user/opt/anaconda3/lib/clang/10.0.0 -I /Users/user/opt/anaconda3/include/python3.8 -I /Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I /src -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -stdlib=libc++ -internal-isystem /Users/user/opt/anaconda3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Users/user/opt/anaconda3/lib/clang/10.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -Ofast -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/user/Documents/python_package_example -ferror-limit 19 -fmessage-length 158 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.16.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/xy/lcpszqt54bg9_4xnrhdk9j500000gp/T/bind_hi-4642ed.o -x c++ src/bind_hi.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include"
ignoring nonexistent directory "/src"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
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:
/Users/user/opt/anaconda3/include/python3.8
/Users/user/opt/anaconda3/bin/../include/c++/v1
/Users/user/opt/anaconda3/lib/clang/10.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
src/bind_hi.cpp:9:10: fatal error: 'pybind11/pybind11.h' file not found
#include <pybind11/pybind11.h>
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [hi..cpython-38-darwin.so] Error 1
This output deviates from that during successful compilation at the line:
ignoring nonexistent directory "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include"

Related

Not able to Cross-compile and link source code using afl-clang-fast++

I am trying to fuzz a simple C++ code using afl plus plus clang compiler (llvm_mode). I'm able to fuzz the code and generate the ARM object file but it fails while linking. I guess i'm missing some linker options. Any help would be appreciated
Following is my command:
afl-clang-fast++ --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
root and sysroot values are as follows
root=/path/to/clang/install_dir
sysroot=/path/to/linarogcc/arm-linux-gnueabihf/libc
From the output, i can conclude that with the help of Linaro tool-chain, compilation is going through but linking is failing
Output:
afl-clang-fast++2.66d by <lszekeres#google.com> in CLASSIC mode
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: arm--linux-gnueabihf
Thread model: posix
InstalledDir: /usr/lib/llvm-6.0/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
"/usr/lib/llvm-6.0/bin/clang" -cc1 -triple armv6kz--linux-gnueabihf -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name TestCodeX86toARM.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu arm1176jzf-s -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi hard -fallow-half-arguments-and-returns -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v -nostdinc++ -resource-dir /usr/lib/llvm-6.0/lib/clang/6.0.0 -I /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/include/c++/v1 -D __AFL_HAVE_MANUAL_CONTROL=1 -D __AFL_COMPILER=1 -D FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -D __AFL_FUZZ_INIT()=int __afl_sharedmem_fuzzing = 1;extern unsigned int *__afl_fuzz_len;extern unsigned char *__afl_fuzz_ptr;unsigned char __afl_fuzz_alt[1024000];unsigned char *__afl_fuzz_alt_ptr = __afl_fuzz_alt; -D __AFL_FUZZ_TESTCASE_BUF=(__afl_fuzz_ptr ? __afl_fuzz_ptr : __afl_fuzz_alt_ptr) -D __AFL_FUZZ_TESTCASE_LEN=(__afl_fuzz_ptr ? *__afl_fuzz_len : (*__afl_fuzz_len = read(0, __afl_fuzz_alt_ptr, 1024000)) == 0xffffffff ? 0 : *__afl_fuzz_len) -D "__AFL_LOOP(_A)=({ static volatile char *_B __attribute__((used)); _B = (char*)\"##SIG_AFL_PERSISTENT##\"; __attribute__((visibility(\"default\"))) int _L(unsigned int) __asm__(\"__afl_persistent_loop\"); _L(_A); })" -D "__AFL_INIT()=do { static volatile char *_A __attribute__((used)); _A = (char*)\"##SIG_AFL_DEFER_FORKSRV##\"; __attribute__((visibility(\"default\"))) void _I(void) __asm__(\"__afl_manual_init\"); _I(); } while (0)" -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 /usr/lib/llvm-6.0/lib/clang/6.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 -O3 -Wno-unused-command-line-argument -fdeprecated-macro -fdebug-compilation-dir /home/user/Tejas/CrossCopileTestCode -ferror-limit 19 -fmessage-length 87 -funroll-loops -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -load /usr/local/lib/afl/afl-llvm-pass.so -o /tmp/TestCodeX86toARM-c0d8ac.o -x c++ TestCodeX86toARM.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-pc-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
/usr/lib/llvm-6.0/lib/clang/6.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.
afl-llvm-pass++2.66d by <lszekeres#google.com> and <adrian.herrera#anu.edu.au>
[+] Instrumented 3 locations (non-hardened mode, ratio 100%).
"/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 -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-c0d8ac.o /usr/local/lib/afl/afl-llvm-rt.o -lc++ -lm /usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.builtins-armhf.a -lc /usr/lib/llvm-6.0/lib/clang/6.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
/usr/local/lib/afl/afl-llvm-rt.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How to use header file <xmmintrin.h> with Yocto-generated SDK?

I have an issue with a Yocto-generated SDK: the header file xmmintrin.h is not found when trying to compile with the SDK. Example:
$ echo '#include <xmmintrin.h>' > t.cpp
$ $CXX $CXXFLAGS -no-canonical-prefixes -c t.cpp
t.cpp:1:10: fatal error: 'xmmintrin.h' file not found
$CXX points to the SDK's clang++.
The verbose output is:
$ $CXX $CXXFLAGS -no-canonical-prefixes -c t.cpp -v
clang version 6.0.0 (git://github.com/llvm-mirror/clang.git ff0c0d8ab3e316bb6e2741fedb3b545e198eab7a) (git://github.com/llvm-mirror/llvm.git 089d4c0c490687db6c75f1d074e99c4d42936a50)
Target: x86_64-poky-linux-musl
Thread model: posix
InstalledDir: /opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/x86_64-poky-linux-musl
Found candidate GCC installation: /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/lib//x86_64-poky-linux-musl/7.3.0
Found candidate GCC installation: /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/lib/gcc/x86_64-poky-linux-musl/7.3.0
Selected GCC installation: /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/lib//x86_64-poky-linux-musl/7.3.0
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/x86_64-poky-linux-musl/x86_64-poky-linux-musl-clang++" -cc1 -triple x86_64-poky-linux-musl -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name t.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -fmath-errno -mfpmath sse -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu core2 -target-feature +sse3 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /home/kamo7631/t.gcno -rpokyurce-dir /opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0 -isysroot /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl -internal-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include/c++/v1 -internal-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/local/include -internal-isystem /opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0/include -internal-externc-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/include -internal-externc-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include -O2 -fdeprecated-macro -fdebug-compilation-dir /home/kamo7631 -ferror-limit 19 -fmessage-length 132 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o t.o -x c++ t.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/local/include"
ignoring nonexistent directory "/opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0/include"
ignoring nonexistent directory "/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include/c++/v1
/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include
End of search list.
t.cpp:1:10: fatal error: 'xmmintrin.h' file not found
#include <xmmintrin.h>
^~~~~~~~~~~~~
1 error generated.
The header file is present as sysroots/x86_64-pokysdk-linux/usr/lib/clang/6.0.0/include/xmmintrin.h, but is not found anywhere in sysroots/core2-64-poky-linux-musl (the target sysroot).
What do I have to change in order to be able to use this and other header files from the SDK?
Please post output of
$CLANGCXX $CXXFLAGS -no-canonical-prefixes -c t.cpp -v
I think the problem is a bug in SDK where compiler include paths are looking for
compiler headers but in wrong directory. Maybe its pointing to sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0/include
you can try to add -I ${OECORE_NATIVE_SYSROOT}/usr/lib/clang/6.0.0/include to your compiler cmdline. also make sure you have sources the SDK environment script which is at the top of SDK install dir, its name starts like this "environment-setup-"

Including header path with -I, but still not found

I'm having a strange error with clang. I'm attempting to build pandas and it's failing to build msgpack. I've added to my search path a folder which contains the file complex.h, and I'm passing the path to this folder as an argument with -I/nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include. However, clang is still failing to find it.
$ ls /nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include | grep complex
complex.h
$ clang -v -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -D__LITTLE_ENDIAN__=1 -Ipandas/src/klib -Ipandas/src -I/nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include -I/nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include -I/nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include/python2.7 -c pandas/msgpack.cpp -o build/temp.macosx-10.7-x86_64-2.7/pandas/msgpack.o
clang version 3.6.2 (tags/RELEASE_362/final)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
"/nix/store/3ipm9yr9jz4mcgc9n2fa85rwrjjk2bi0-clang-3.6.2/bin/clang-3.6" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -disable-free -disable-llvm-verifier -main-file-name msgpack.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -gdwarf-2 -dwarf-column-info -coverage-file /var/folders/wl/723blrkd0q70mdnf5flcvqsw00010q/T/pandas-build/pandas-0.16.2/build/temp.macosx-10.7-x86_64-2.7/pandas/msgpack.o -nostdsysteminc -resource-dir /nix/store/3ipm9yr9jz4mcgc9n2fa85rwrjjk2bi0-clang-3.6.2/bin/../lib/clang/3.6.2 -idirafter /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include -isystem /nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include -isystem /nix/store/whdp09gkfw7jvjp1l6i746cncf83p901-libc++-3.6.2/include -isystem /nix/store/9zqc1nvla9f3kbra4734wx7hdxafgzpc-openblas-0.2.14/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -D NDEBUG -D __LITTLE_ENDIAN__=1 -I pandas/src/klib -I pandas/src -I /nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include -I /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include -I /nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include/python2.7 -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks -O3 -Wall -Wstrict-prototypes -Wno-multichar -Wno-deprecated-declarations -fdeprecated-macro -fdebug-compilation-dir /var/folders/wl/723blrkd0q70mdnf5flcvqsw00010q/T/pandas-build/pandas-0.16.2 -ferror-limit 19 -fmessage-length 0 -fwrapv -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o build/temp.macosx-10.7-x86_64-2.7/pandas/msgpack.o -x c++ pandas/msgpack.cpp
clang -cc1 version 3.6.2 based upon LLVM 3.6.2 default target x86_64-apple-darwin13.4.0
#include "..." search starts here:
#include <...> search starts here:
pandas/src/klib
pandas/src
/nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include
/nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include
/nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include/python2.7
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
/nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include
/nix/store/whdp09gkfw7jvjp1l6i746cncf83p901-libc++-3.6.2/include
/nix/store/9zqc1nvla9f3kbra4734wx7hdxafgzpc-openblas-0.2.14/include
/nix/store/3ipm9yr9jz4mcgc9n2fa85rwrjjk2bi0-clang-3.6.2/bin/../lib/clang/3.6.2/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
End of search list.
In file included from pandas/msgpack.cpp:252:
In file included from /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
In file included from /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1804:
/nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by " \
^
In file included from pandas/msgpack.cpp:254:
pandas/src/msgpack/unpack.h:72:11: warning: comparison of constant 9223372036854775807 with expression of type 'uint32_t' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
if (d > LONG_MAX) {
~ ^ ~~~~~~~~
pandas/msgpack.cpp:447:14: fatal error: 'complex' file not found
#include <complex>
^
2 warnings and 1 error generated.

C++11 compilation issues in codeblocks

I cant seem to get codeblocks 13.12 to compile c++11 correctly in both clang++ and g++. I have attached the -std=c++11 and -stdlib=libc++ when compiling with clang++. This leads to a linking error. For g++ when you add -std=c++11 or -std=c++0x, the compiler cannot find the random header. When I compiled the code manually in a terminal using both clang++ and g++, none of these errors occurred.
The full linker errors are too long to post so i will just post the information given from the -v invocation.
In codeblocks using clang++ with -std=c++11 and -stdlib=libc++:
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o bin/Release/p_class_test obj/Release/Thread_Pool/thread_helper.o obj/Release/Thread_Pool/thread_pool.o obj/Release/Desktop/kmap_testing/hash_methods.o obj/Release/Desktop/p_class_test/p_classtest.o obj/Release/Desktop/p_class_test/refmanager.o -lstdc++ -lSystem /usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
compiling in terminal using clang++ with -std=c++11 and -stdlib=libc++:
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name thread_helper.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /usr/bin/../lib/clang/5.1 -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool/ -I /Users/zacharykraus/Desktop/kmap_testing/ -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zacharykraus -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/thread_helper-57c077.o -x c++ /Users/zacharykraus/Thread_Pool/thread_helper.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/5.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name thread_pool.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /usr/bin/../lib/clang/5.1 -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool/ -I /Users/zacharykraus/Desktop/kmap_testing/ -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zacharykraus -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/thread_pool-321d19.o -x c++ /Users/zacharykraus/Thread_Pool/thread_pool.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/5.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name hash_methods.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /usr/bin/../lib/clang/5.1 -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool/ -I /Users/zacharykraus/Desktop/kmap_testing/ -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zacharykraus -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/hash_methods-b28b1b.o -x c++ /Users/zacharykraus/Desktop/kmap_testing/hash_methods.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/5.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name p_classtest.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /usr/bin/../lib/clang/5.1 -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool/ -I /Users/zacharykraus/Desktop/kmap_testing/ -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zacharykraus -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/p_classtest-ad56a5.o -x c++ /Users/zacharykraus/Desktop/p_class_test/p_classtest.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/5.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name refmanager.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /usr/bin/../lib/clang/5.1 -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool/ -I /Users/zacharykraus/Desktop/kmap_testing/ -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zacharykraus -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/refmanager-d17474.o -x c++ /Users/zacharykraus/Desktop/p_class_test/refmanager.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/5.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o nork /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/thread_helper-57c077.o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/thread_pool-321d19.o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/hash_methods-b28b1b.o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/p_classtest-ad56a5.o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T/refmanager-d17474.o -lc++ -lSystem /usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
Unfortunately I cant make the comparison between codeblocks g++ and g++ in the terminal.
But based on the output from the two different compilations in clang. It appears codeblocks is not using the libc++ library during the linking step. How do you get codeblocks to use the correct libraries on linking for clang++?
I assume based on the clang problem g++ in codeblocks is using an older c++ 03 library even when telling the compiler to switch to c++11. But unfortunately I dont know how to confirm this.
I found the answer to clang++.
Apparently you have to add -stdlib=libc++ as both a compiler flag and a linking flag.
The linkage output turns to
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o bin/Release/p_class_test obj/Release/Thread_Pool/thread_helper.o obj/Release/Thread_Pool/thread_pool.o obj/Release/Desktop/kmap_testing/hash_methods.o obj/Release/Desktop/p_class_test/p_classtest.o obj/Release/Desktop/p_class_test/refmanager.o -lc++ -lSystem /usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
which clearly shows the correct library being used.
The g++ problem occurs because even though codeblocks outputs that is it compiling with g++ in actually it using clang++ libraries as part of the compilation and linking process. Though based on the output its not 100% clear if the g++ compiler and its includes are being called. To fix the problem, you need to add -stdlib=libc++ flag for both compilation and linking. As proof that codeblocks on apple is in fact using the clang libraries under the hood, I have attached the output from -v during both linking and compiling and the commands used by codeblocks.
Here is the information for linking:
g++ -o bin/Debug/p_class_test obj/Debug/Thread_Pool/thread_helper.o obj/Debug/Thread_Pool/thread_pool.o obj/Debug/Desktop/kmap_testing/hash_methods.o obj/Debug/Desktop/p_class_test/p_classtest.o obj/Debug/Desktop/p_class_test/refmanager.o -v -stdlib=libc++
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o bin/Debug/p_class_test obj/Debug/Thread_Pool/thread_helper.o obj/Debug/Thread_Pool/thread_pool.o obj/Debug/Desktop/kmap_testing/hash_methods.o obj/Debug/Desktop/p_class_test/p_classtest.o obj/Debug/Desktop/p_class_test/refmanager.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
And here is the information for compiling:
g++ -g -std=c++11 -stdlib=libc++ -v -I/Users/zacharykraus/Desktop/p_class_test/ -I/Users/zacharykraus/Thread_Pool -I/Users/zacharykraus/Desktop/kmap_testing -c /Users/zacharykraus/Desktop/p_class_test/refmanager.cpp -o obj/Debug/Desktop/p_class_test/refmanager.o
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name refmanager.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -gdwarf-2 -coverage-file /Users/zacharykraus/Desktop/p_class_test/obj/Debug/Desktop/p_class_test/refmanager.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool -I /Users/zacharykraus/Desktop/kmap_testing -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zacharykraus/Desktop/p_class_test -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o obj/Debug/Desktop/p_class_test/refmanager.o -x c++ /Users/zacharykraus/Desktop/p_class_test/refmanager.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
After a lot of annoyance I finally figured out what the problem with g++ was on codeblocks. The problem is that codeblocks when calling g++ does not use your executable path. Instead it uses your toolchain executable path in the Compiler settings. My toolchain executable path was set to /usr/bin where the apple version of g++ resides. This version actually calls clang++ through a complex series of calls. All I needed to do to fix the issue was to change the toolchain executable path to /usr/local/bin where my actual gnu compiler resides. After this change, I was able to get rid of -stdlib=libc++ and my compilation and linking readouts are below.
compilation:
g++ -g -std=c++11 -v -I/Users/zacharykraus/Desktop/p_class_test/ -I/Users/zacharykraus/Thread_Pool -I/Users/zacharykraus/Desktop/kmap_testing -c /Users/zacharykraus/Thread_Pool/thread_helper.cpp -o obj/Debug/Thread_Pool/thread_helper.o
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-apple-darwin12.5.0
Configured with: ../gcc-4.8.1/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.8.5' '-g' '-std=c++11' '-v' '-I' '/Users/zacharykraus/Desktop/p_class_test/' '-I' '/Users/zacharykraus/Thread_Pool' '-I' '/Users/zacharykraus/Desktop/kmap_testing' '-c' '-o' 'obj/Debug/Thread_Pool/thread_helper.o' '-shared-libgcc' '-mtune=core2'
/usr/local/libexec/gcc/x86_64-apple-darwin12.5.0/4.8.1/cc1plus -quiet -v -I /Users/zacharykraus/Desktop/p_class_test/ -I /Users/zacharykraus/Thread_Pool -I /Users/zacharykraus/Desktop/kmap_testing -D__DYNAMIC__ /Users/zacharykraus/Thread_Pool/thread_helper.cpp -fPIC -feliminate-unused-debug-symbols -quiet -dumpbase thread_helper.cpp -mmacosx-version-min=10.8.5 -mtune=core2 -auxbase-strip obj/Debug/Thread_Pool/thread_helper.o -g -std=c++11 -version -o /var/folders/k5/ywc_m0js3z3byh3yqwbfmfj00000gn/T//ccVidneY.s
GNU C++ (GCC) version 4.8.1 (x86_64-apple-darwin12.5.0)
compiled by GNU C version 4.8.1, GMP version 4.3.1, MPFR version 2.4.1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../../../x86_64-apple-darwin12.5.0/include"
#include "..." search starts here:
#include <...> search starts here:
/Users/zacharykraus/Desktop/p_class_test/
/Users/zacharykraus/Thread_Pool
/Users/zacharykraus/Desktop/kmap_testing
/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../../../include/c++/4.8.1
/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../../../include/c++/4.8.1/x86_64-apple-darwin12.5.0
/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../../../include/c++/4.8.1/backward
/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/include
/usr/local/include
/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/include-fixed
/usr/include
/System/Library/Frameworks
/Library/Frameworks
End of search list.
linking:
g++ -o bin/Debug/p_class_test obj/Debug/Thread_Pool/thread_helper.o obj/Debug/Thread_Pool/thread_pool.o obj/Debug/Desktop/kmap_testing/hash_methods.o obj/Debug/Desktop/p_class_test/p_classtest.o obj/Debug/Desktop/p_class_test/refmanager.o -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.5.0/4.8.1/lto-wrapper
Target: x86_64-apple-darwin12.5.0
Configured with: ../gcc-4.8.1/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 4.8.1 (GCC)
COMPILER_PATH=/usr/local/libexec/gcc/x86_64-apple-darwin12.5.0/4.8.1/:/usr/local/libexec/gcc/x86_64-apple-darwin12.5.0/4.8.1/:/usr/local/libexec/gcc/x86_64-apple-darwin12.5.0/:/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/:/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/
LIBRARY_PATH=/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/:/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.8.5' '-o' 'bin/Debug/p_class_test' '-v' '-shared-libgcc' '-mtune=core2'
/usr/local/libexec/gcc/x86_64-apple-darwin12.5.0/4.8.1/collect2 -dynamic -arch x86_64 -macosx_version_min 10.8.5 -weak_reference_mismatches non-weak -o bin/Debug/p_class_test -L/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1 -L/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../.. obj/Debug/Thread_Pool/thread_helper.o obj/Debug/Thread_Pool/thread_pool.o obj/Debug/Desktop/kmap_testing/hash_methods.o obj/Debug/Desktop/p_class_test/p_classtest.o obj/Debug/Desktop/p_class_test/refmanager.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
collect2 version 4.8.1
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.8.5 -weak_reference_mismatches non-weak -o bin/Debug/p_class_test -L/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1 -L/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/../../.. obj/Debug/Thread_Pool/thread_helper.o obj/Debug/Thread_Pool/thread_pool.o obj/Debug/Desktop/kmap_testing/hash_methods.o obj/Debug/Desktop/p_class_test/p_classtest.o obj/Debug/Desktop/p_class_test/refmanager.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
#(#)PROGRAM:ld PROJECT:ld64-236.4
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 armv6m armv7m armv7em
Library search paths:
/usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1
/usr/local/lib
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/

How to compile C++11 with clang 3.2 on OSX lion?

I am trying to compile the following C++ program which relies on the C++11 <thread> header. I am trying to do this on OSX Lion.
#include <iostream>
#include <thread>
#include <vector>
void hello()
{
std::cout << "Hello from thread " << std::this_thread::get_id() << std::endl;
}
int main()
{
std::vector<std::thread> threads;
for(int i = 0; i < 5; i++)
{
threads.push_back(std::thread(hello));
}
for(auto& thread: threads)
{
thread.join();
}
return 0;
}
The above program compiles fine with g++ 4.7 which I installed using the homebrew package manager. However when trying to compile the above program with clang 3.2 (also installed using the homebrew package manager) I get the following error message:
Zameers-MacBook-Air:tmp zmanji$ clang++ -v -std=c++11 test.cpp
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
"/usr/local/Cellar/llvm/3.2/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -v -resource-dir /usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2 -fmodule-cache-path /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/clang-module-cache -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zmanji/tmp -ferror-limit 19 -fmessage-length 101 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/test-Zkjucl.o -x c++ test.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-apple-darwin11.3.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
test.cpp:2:10: fatal error: 'thread' file not found
#include <thread>
^
1 error generated.
It seems that clang cannot find the <thread> header but I am not sure why.
Edit:
I tried sharth's answer below and now I am getting the error that the <iostream> header does not exist.
Zameers-MacBook-Air:tmp zmanji$ clang++ -v -std=c++11 -stdlib=libc++ test.cpp
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
"/usr/local/Cellar/llvm/3.2/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -v -resource-dir /usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2 -fmodule-cache-path /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/clang-module-cache -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/zmanji/tmp -ferror-limit 19 -fmessage-length 203 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/qf/j_7_sw0n093gn1y0mtsyztxh0000gn/T/test-k2Alf4.o -x c++ test.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-apple-darwin11.3.0
ignoring nonexistent directory "/usr/local/Cellar/llvm/3.2/bin/../lib/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
You need to use libc++ instead of libstdc++.
clang++ -std=c++11 -stdlib=libc++ foo.cc