Ошибка компоновщика с boost :: program_options и C ++ 11 в OSX

Я построил повышение таким образом:

~/Downloads/boost_1_52_0
$ sudo ./b2 --build-dir=build --layout=system -j4 toolset=clang variant=release link=shared runtime-link=shared threading=multi cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" --without-mpi --without-python install

а затем попытался скомпилировать первый пример программы

~/Downloads/boost_1_52_0
$ cd libs/program_options/example                                                                                                                             [18:35:25]

~/Downloads/boost_1_52_0/libs/program_options/example
$ c++ -v -std=c++11 -stdlib=libc++ -lboost_program_options -o first first.cpp                                                                                 [18:38:32]
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name first.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 134.9 -v -resource-dir /usr/bin/../lib/clang/4.1 -fmodule-cache-path /var/folders/sq/nfthwlb93k5bl9qyrjbvfylm0000gn/T/clang-module-cache -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/lexi/Downloads/boost_1_52_0/libs/program_options/example -ferror-limit 19 -fmessage-length 169 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/sq/nfthwlb93k5bl9qyrjbvfylm0000gn/T/first-oIjAae.o -x c++ first.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin11.4.2
ignoring nonexistent directory "/usr/include/c++/v1"#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/c++/v1
/usr/local/include
/usr/bin/../lib/clang/4.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.7.0 -o first -lcrt1.10.6.o -lboost_program_options /var/folders/sq/nfthwlb93k5bl9qyrjbvfylm0000gn/T/first-oIjAae.o -lc++ -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) in first-oIjAae.o
"boost::program_options::validation_error::what() const", referenced from:
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in first-oIjAae.o
vtable for boost::program_options::invalid_option_value in first-oIjAae.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in first-oIjAae.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in first-oIjAae.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in first-oIjAae.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Что я делаю неправильно? Единственная похожая ошибка, которую я мог найти, была Ошибка компоновщика с Boost & C ++ на OSX но он использует CMake, gcc и c ++ 03, и его решение «Я перекомпилировал Boost, и это сработало» не особенно полезно.

Это также определенно не ошибка кода, так как bjam может построить пример, но я не понимаю достаточного количества compiler-fu, чтобы иметь возможность посмотреть на вывод и сказать: «О, вот как вы это делаете!»

~/Downloads/boost_1_52_0/libs/program_options/example
$ ../../../b2 -ad+2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" first
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/example/clang-darwin-4.2.1/debug/link-static/first.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/example/clang-darwin-4.2.1/debug/link-static/first.o" "first.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/cmdline.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/cmdline.o" "../../../libs/program_options/src/cmdline.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/config_file.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/config_file.o" "../../../libs/program_options/src/config_file.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/options_description.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/options_description.o" "../../../libs/program_options/src/options_description.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/parsers.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/parsers.o" "../../../libs/program_options/src/parsers.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/variables_map.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/variables_map.o" "../../../libs/program_options/src/variables_map.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/value_semantic.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/value_semantic.o" "../../../libs/program_options/src/value_semantic.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/positional_options.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/positional_options.o" "../../../libs/program_options/src/positional_options.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/utf8_codecvt_facet.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/utf8_codecvt_facet.o" "../../../libs/program_options/src/utf8_codecvt_facet.cpp"
In file included from ../../../libs/program_options/src/utf8_codecvt_facet.cpp:15:
In file included from ../../../boost/detail/utf8_codecvt_facet.ipp:13:
../../../boost/detail/utf8_codecvt_facet.hpp:171:17: warning: 'boost::program_options::detail::utf8_codecvt_facet::do_length' hides overloaded virtual function [-Woverloaded-virtual]
virtual int do_length(
^
/usr/bin/../lib/c++/v1/__locale:920:17: note: hidden overloaded virtual function 'std::__1::codecvt<wchar_t, char, __mbstate_t>::do_length' declared here
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
^
1 warning generated.
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/convert.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/convert.o" "../../../libs/program_options/src/convert.cpp"
In file included from ../../../libs/program_options/src/convert.cpp:19:
In file included from ../../../boost/program_options/detail/utf8_codecvt_facet.hpp:19:
../../../boost/detail/utf8_codecvt_facet.hpp:171:17: warning: 'boost::program_options::detail::utf8_codecvt_facet::do_length' hides overloaded virtual function [-Woverloaded-virtual]
virtual int do_length(
^
/usr/bin/../lib/c++/v1/__locale:920:17: note: hidden overloaded virtual function 'std::__1::codecvt<wchar_t, char, __mbstate_t>::do_length' declared here
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
^
1 warning generated.
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/winmain.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/winmain.o" "../../../libs/program_options/src/winmain.cpp"
clang-darwin.compile.c++ ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/split.o

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -I"../../.." -c -o "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/split.o" "../../../libs/program_options/src/split.cpp"
RmTemps ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/libboost_program_options.a(clean)

rm -f "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/libboost_program_options.a"
clang-darwin.archive ../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/libboost_program_options.a

"ar"  rc "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/libboost_program_options.a" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/cmdline.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/config_file.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/options_description.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/parsers.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/variables_map.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/value_semantic.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/positional_options.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/utf8_codecvt_facet.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/convert.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/winmain.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/split.o""ranlib" -cs "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/libboost_program_options.a"
clang-darwin.link ../../../bin.v2/libs/program_options/example/clang-darwin-4.2.1/debug/link-static/first

"clang++" -stdlib=libc++ -stdlib=libc++  -o "../../../bin.v2/libs/program_options/example/clang-darwin-4.2.1/debug/link-static/first" "../../../bin.v2/libs/program_options/example/clang-darwin-4.2.1/debug/link-static/first.o" "../../../bin.v2/libs/program_options/build/clang-darwin-4.2.1/debug/link-static/libboost_program_options.a"    -g~/Downloads/boost_1_52_0/libs/program_options/example
$ ../../../bin.v2/libs/program_options/example/clang-darwin-4.2.1/debug/link-static/first
Compression level was not set.

3

Решение

Сначала вам нужно Libc ++ ABI.

Во-вторых, вы должны добавить -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc или же -lc++abi на вашу команду компоновщика. Для одного файла это должно выглядеть так:

`clang++ -stdlib=libc++ helloworld.cpp -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc`

Или это:

`clang++ -stdlib=libc++ helloworld.cpp -lc++abi`

Больше информации на официальной странице Libc ++

2

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]