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

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.

Related

Compiler error of clang++ 8.0 -- Segmentation fault -- on Mac OSX Sierra 10.12.3

I recently upgraded my OSX from El Capitan to Sierra. The upgrade starts generating compiler errors when using clang++ for one of my projects. I tried it on other projects which do not generate the same errors. Here's the error message.
clang++ -v -O3 -std=c++11 -stdlib=libc++ -g -Wall -I/Users/kevincha/projects/git_hub/DRAMPower/src -I/usr/local/include -I/usr/local/Cellar/boost/1.63.0/include -DRAMULATOR -o ramulator src/Main.cpp obj/ALDRAM.o obj/Cache.o obj/Config.o obj/Controller.o obj/DDR3.o obj/DDR4.o obj/DSARP.o obj/GDDR5.o obj/HBM.o obj/LPDDR4.o obj/Packet.o obj/Processor.o obj/Refresh.o obj/SALP.o obj/StatType.o obj/TLDRAM.o obj/WideIO.o obj/WideIO2.o
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -I /Users/kevincha/projects/git_hub/DRAMPower/src -I /usr/local/include -I /usr/local/Cellar/boost/1.63.0/include -D RAMULATOR -stdlib=libc++ -O3 -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/kevincha/projects/git_hub/ramulator_power -ferror-limit 19 -fmessage-length 270 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/cn/jclpg1w53fd_gbsnwtjzsc7w0000gn/T/Main-4d31a3.o -x c++ src/Main.cpp
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.4.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/Users/kevincha/projects/git_hub/DRAMPower/src
/usr/local/Cellar/boost/1.63.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/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
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to http://developer.apple.com/bugreporter/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/cn/jclpg1w53fd_gbsnwtjzsc7w0000gn/T/Main-ae92f3.cpp
clang: note: diagnostic msg: /var/folders/cn/jclpg1w53fd_gbsnwtjzsc7w0000gn/T/Main-ae92f3.sh
clang: note: diagnostic msg:
********************
make: *** [ramulator] Error 254
This was a clang compiler bug, now fixed in the latest (beta) Xcode:
Xcode 8.3 beta 3 (8W132p)
Posted Date: Feb 20th, 2017
↳ https://developer.apple.com/download/

C++ libraries on mac not compiling with g++ my_program.cpp -o my_program

I have recently attempted to download (using Homebrew) Eigen (a C++ library) and compile the example program on Eigen's website https://eigen.tuxfamily.org/dox/GettingStarted.html.
I get a error in terminal that is:
EigenExample1.cpp:10:10: fatal error: 'Eigen/Dense' file not found #include < Eigen/Dense >
I have double checked to make sure homebrew was updated and the eigen3 folder does exist in /usr/local/include. In addition I do have command line tools installed and cpp -v returns:
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -I /usr/include -fdebug-compilation-dir /Users/name/MNISTNeuralNetwork/Eigen -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -traditional-cpp -o - -x c -
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.3.0
ignoring duplicate directory "/usr/include"
as it is a non-system directory that duplicates a system directory
\#include "..." search starts here:
\#include <...> search starts here:
/usr/local/include
/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
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
When you install using Homebrew, the Eigen directory is nested inside include/eigen3. You should be able to compile with the following flags:
g++ -I "$(brew --prefix eigen)/include/eigen3" my_program.cpp -o my_program
Indeed, this is how the Homebrew installation is tested.

'unordered_map' file not found error when compiling with Xcode 7.3.1

A file in my project fails to compile with
'unordered_map' file not foundIn file included from ...
This is despite I compile with -std=c++ and a directory that has unordered_map in it is in system include paths.
clang -std=c++14 -x c++ -v -E /dev/null
results in the output below. /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 does contain unordered_map.
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 264.3.102 -v -dwarf-column-info -resource-dir /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0 -stdlib=libc++ -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /Users/ovz -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ /dev/null
clang -cc1 version 7.3.0 (clang-703.0.31) default target x86_64-apple-darwin15.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here: /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/include
/Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
You need to pass this option:
-stdlib=libc++
to select libc++.
I heard people said that AppleClang uses an old version of libstdc++ (probably from g++) by default. I'm not sure why they made that decision (needless to say, it's understandable in GNU/Linux because most of the time, GNU/Linux is shipped with libstdc++ from g++).

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/

Compiling CGAL programs on mac, installed using macports

I am working on a project that requires CGAL running on a mac and am very new to C++ in general. I installed CGAL using macports using the command
sudo port install cgal
The installation completed and the .h files were placed in
/opt/local/include/cgal
I copied the tutorial program into a .cpp file and compiled using
g++ -lcgal -I/opt/local/include/ vec.cpp
This returns the error
ld: library not found for -lcgal
clang: error: linker command failed with exit code 1 (use -v to see invocation)
g++ -lcgal -v -I/opt/local/include/ vec.cpp returns
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.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 vec.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 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -I /opt/local/include -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/sujeath/C practice -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/tm/bgg4k0xs4v36pzwxvsrqtsb00000gn/T/vec-0a56fb.o -x c++ vec.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.2.0
ignoring nonexistent directory "/usr/include/c++/v1"
\#include "..." search starts here:
\#include search starts here:
/opt/local/include
/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.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o a.out /var/folders/tm/bgg4k0xs4v36pzwxvsrqtsb00000gn/T/vec-0a56fb.o -lcgal -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
ld: library not found for -lcgal
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using Mavericks BTW and gnu gcc
Thanks!
so, first of all, I'm new on stackoverflow and actually would have preferred to add a comment rather then posting an answer as I'm pretty new to the C++/Mac world too.
Stated this disclaimer I would like to point out a two things that I saw "parsing" the output you posted:
You're calling g++, however, you're using clang to compile (default on OS X Mavericks) as /usr/bin/g++ points to /usr/bin/clang++
I think the cgal library is not on your search path. Marc Glisse pointed you to the -L option of the ld command that let you define further search directories. Probably -L/opt/local/lib might work for you using Macports (I didn't use Macports for a long time so I'm not sure if that's the correct path for the libraries).
Hope this helps.