c++ - Using c++11 in MacOS X and compiled Boost libraries conundrum -
i trying compile c++ project uses c++11 standards extensively. going -std=c++11, until tried use unordered_map , macos doesn't have unordered_map header file anywhere in usr/include.
i did research , found using -stdlib=libc++ fix (not sure how, seems magic me if include file in filesystem). did. compiled well, linker cannot link boost::program_options program uses extensively. without -stdlib=libc++, boost links perfectly, lose unordered_map.
what should have latest c++11 features mac os clang++ compiler , still able link boost libraries (which built sources on mac)
ps: works fine in arch linux box
my makefile:
libs = -lboost_program_options cxxflags = -stdlib=libc++ -std=c++11 -wall -g obj = fastq.o fastq_reader.o main.o degenerate.o interleave.o complement.o interval_utils.o interval.o interval_utils_test_tool.o
foghorn: $(obj) $(link.cc) -o $@ $^ $(libs)
the output using -stdlib=libc++
$ make c++ -stdlib=libc++ -std=c++11 -wall -g -c -o fastq.o fastq.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o fastq_reader.o fastq_reader.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o main.o main.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o degenerate.o degenerate.cpp c++ -stdlib=libc++ -std=c++11 -wall -g
-c -o interleave.o interleave.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o complement.o complement.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o interval_utils.o interval_utils.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o interval.o interval.cpp c++ -stdlib=libc++ -std=c++11 -wall -g -c -o interval_utils_test_tool.o interval_utils_test_tool.cpp c++ -stdlib=libc++ -std=c++11 -wall -g
-o foghorn fastq.o fastq_reader.o main.o degenerate.o interleave.o complement.o interval_utils.o interval.o interval_utils_test_tool.o -lboost_program_options undefined symbols architecture x86_64: "boost::program_options::to_internal(std::__1::basic_string, std::__1::allocator > const&)", referenced from: std::__1::vector, std::__1::allocator >, std::__1::allocator, std::__1::allocator > > > boost::program_options::to_internal, std::__1::allocator >(std::__1::vector, std::__1::allocator >, std::__1::allocator, std::__1::allocator > > > const&) in main.o
... [clipped output readability]
ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) make: * [foghorn] error 1
after lot of research, learned following:
- everything on macos x built using stdlibc++ (including install homebrew -- case)
- stdlibc++ comes gcc 4.2 not implement many of features of c++11. examples unordered_map, to_string, stoi, ... libc++ does.
- libc++ installed in macos xcode.
conclusion:
- if you're using c++11, have use -stdlib=libc++.
- if want use boost or other library, have recompile them -stdlib=libc++ well.
so downloaded boost sources website, , compiled using following command line:
bootstrap.sh && b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++" install
if use homebrew, can , right thing you:
brew install boost --c++11
Comments
Post a Comment