Why is clang++ linking to gcc? - c++

I have a simple "Hello, world" style program that I'm compiling with clang++ on FreeBSD:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
cout << "Oh, hello" << endl;
return EXIT_SUCCESS;
}
Which I compile with clang++ and its libc++:
$ clang++ -stdlib=libc++ -v ohhello.cpp
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin
"/usr/bin/clang++" -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name ohhello.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/3.8.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /usr/home/mike/projects/ohhello -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/ohhello-050a75.o -x c++ ohhello.cpp
clang -cc1 version 3.8.0 based upon LLVM 3.8.0 default target x86_64-unknown-freebsd11.0
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/v1
/usr/bin/../lib/clang/3.8.0/include
/usr/include
End of search list.
"/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/ohhello-050a75.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
In the linker step I see "-lgcc" and "-lgcc_s" multiple times. Why is clang++ trying to link against gcc if it's using libc++ (not libstdc++)?
Thanks

libgcc is not gcc. It is a small, non compiler-specific C library. It is provided by gcc, but it is not specific to the compiler.

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)

Clang without GCC or MSVC

I'd like to use clang without GCC on Linux and without MSVC on Windows. My understanding is that this wasn't possible in the past due to:
A LLVM linker wasn't available.
A compatible STL wasn't available.
However, my impression what that this should be possible with v8.0.0 as there is now a viable linker and a compatible STL library.
Unfortunately, I get different errors on Linux and Windows when exercising this scenario (see more info below).
Can you help me out with this? Unfortunately, I've found it a bit challenging to find a definitive answer through various searches.
Thanks for the help!
Test Code: test.cpp
#include <vector>
#include <iostream>
int main(void) {
std::vector<int> const v{ 1, 2, 3 };
std::cout << "Hello world\n";
std::cout << v[0] << "\n";
return 0;
}
Linux output
The following output is from Windows Subsystem for Linux, but the behavior is the same on a proper Linux install.
clang -v /mnt/c/Temp/test.cpp -I/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.1
"/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin/clang-8" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0 -I /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /mnt/c/Code/v3/Common/cpp/Clang/8 -ferror-limit 19 -fmessage-length 200 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-284194.o -x c++ /mnt/c/Temp/test.cpp -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
/usr/local/include
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include
/usr/include
End of search list.
In file included from /mnt/c/Temp/test.cpp:1:
In file included from /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/vector:273:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/__config:206:12: fatal error: 'features.h' file not found
# include <features.h>
^~~~~~~~~~~~
1 error generated.
Windows Output
clang -v c:\temp\test.cpp
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\bin
clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
"C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -v -resource-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0\\include" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\include\\c++\\v1" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\Catch2\\v2.7.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\GSL\\v2.0.0\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8" -ferror-limit 19 -fmessage-length 200 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\brownell\\AppData\\Local\\Temp\\test-9329b0.o" -x c++ "c:\\temp\\test.cpp" -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\lib\clang\8.0.0\include
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1
C:\Code\v3\Common\cpp\Common\Libraries\C++\Catch2\v2.7.0
C:\Code\v3\Common\cpp\Common\Libraries\C++\GSL\v2.0.0\include
End of search list.
In file included from c:\temp\test.cpp:1:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\vector:274:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\iosfwd:96:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
For linux
On linux clag will default to using gnu's implementation of the standard library which is libstdc++. To use llvm's implementation - libc++ - you first need to install it. On ubuntu, for instance: sudo apt install libc++-9-dev libc++abi-9-dev. You might need to add the apple repos. Follow these instructions for more systems and latest versions. Then you need to explicit specify it when compiling: -stdlib=libc++. Please see https://libcxx.llvm.org/docs/UsingLibcxx.html
For linking install lld (sudo apt install lld-9) then specify it when compiling with -fuse-ld=lld

Issue with executing a.out file (C++) MacOS Sierra 10.12.1

I just updated to Sierra and it seems my compiler fell apart for some reason.
The code I wrote worked fine before the update, so I'm sure its not an issue there but now it just isn't working what so ever when I try to execute it.
Here is the output.
$ g++ source.cpp
$ ./a.out
dyld: mach-o, but built for simulator (not macOS)
Abort trap: 6
Running G++ with verbose for #NulledPointer
$ g++ --verbose source.cpp
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin16.1.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-ios7.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name source.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 274.1 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -stdlib=libc++ -Wno-error -fdeprecated-macro -fdebug-compilation-dir /Users/USERNAME/FILE_DIRECTORY/ -ferror-limit 19 -fmessage-length 130 -stack-protector 1 -fblocks -fobjc-runtime=ios-7.0.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/kr/tvqfrgdx2w32m0c9fq96zddc0000gn/T/source-355902.o -x c++ source.cpp
clang -cc1 version 8.0.0 (clang-800.0.38) default target x86_64-apple-darwin16.1.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/System/Library/Frameworks (framework directory)
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -ios_simulator_version_min 7.0.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -o a.out /var/folders/kr/tvqfrgdx2w32m0c9fq96zddc0000gn/T/source-355902.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.ios.a
Error from running that command NulledPointer posted.
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk'
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
In file included from source.cpp:10:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:215:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:10: fatal error:
'wchar.h' file not found
#include <wchar.h> // for mbstate_t
^
1 error generated.
There are multiple options:
Try installing missing tools (if any) using xcode-select --install and try compiling. If that fails,
Try running gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk source.cpp. This obviously assuming you have SDK installed in that location. Replace with whatever location exist there.

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/

linker command failed, sdl

I'm trying to compile my very first SDL program, but it doesn't compile.By the way, this shouldn't be about setting up the library I guess because I think that I installed the library properly.
This is my command :
g++ main.cpp -o main -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2
This is my code :
#include <iostream>
#include <SDL.h>
int main(int argc, char **argv){
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_Quit();
return 0;
}
And this is the error message :
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Invocation :
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -I /Library/Frameworks/SDL2.framework/Headers -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/yunusaydin -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/ss/mltsqt6n3jn2kv85gmyn060r0000gn/T/main-Ref4XX.o -x c++ main.cpp
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.1.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Library/Frameworks/SDL2.framework/Headers
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -o main /var/folders/ss/mltsqt6n3jn2kv85gmyn060r0000gn/T/main-Ref4XX.o -framework SDL2 -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a
ld: framework not found SDL2
What am I doing wrong? Thanks for help :)
Finally, this command works :
g++ main.cpp -o main -I/Library/Frameworks/SDL2.framework/Headers -F/Library/Frameworks -framework SDL2
/Library/Frameworks/SDL2.framework/Headers probably does not exist on your system.