私はまだ libc++ とブーストに苦労しています。
ここのようにlibc ++でブーストをコンパイルしました: Clang ++ / libc ++でBoostをコンパイル/リンクする方法は?
今、私は自分のマシンの1つでこのコンパイルエラーを見ていますが、もう1つは正確なコードで完全にうまくコンパイルされています。どちらもコンパイラのバージョンは同じで、環境変数も同じです。
エラーは次のとおりです。
Linking CXX executable main
/opt/local/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/usr/bin/clang++ -arch x86_64 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libc++ CMakeFiles/main.dir/main.cpp.o -o main /usr/lib/libpython2.7.dylib /opt/local/lib/libboost_program_options-mt-d.a /opt/local/lib/libboost_filesystem-mt-d.a /opt/local/lib/libboost_system-mt.a /opt/local/lib/libboost_date_time-mt.a /opt/local/lib/libboost_python-mt.a /opt/local/lib/libboost_log-mt.a /opt/local/lib/libboost_thread-mt.a
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6appendIPwEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueERS5_E4typeES9_S9_", referenced from:
std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > boost::detail::convert<wchar_t, char, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > >) in libboost_program_options-mt-d.a(convert.o)
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendIPcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueERS5_E4typeES9_S9_", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::detail::convert<char, wchar_t, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > > >(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > >) in libboost_program_options-mt-d.a(convert.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
ABI の非互換性の問題がまだ残っていますか?
コードは次のとおりです。
#include <iostream>
#include <string>
#include <tuple>
#include <mutex>
#include <boost/filesystem.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>
#include <boost/program_options.hpp>
#include <CoreFoundation/CoreFoundation.h>
namespace po = boost::program_options;
int main(int ac, char* av[])
{
using namespace std;
std::mutex mymutex;
std::tuple<int, int ,char> mytuple;
boost::filesystem::path mypath("/usr/local/bin");
boost::filesystem::path agaain("/usr");
try {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<double>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 0;
}
if (vm.count("compression")) {
cout << "Compression level was set to "
<< vm["compression"].as<double>() << ".\n";
} else {
cout << "Compression level was not set.\n";
}
}
catch(exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
}
catch(...) {
cerr << "Exception of unknown type!\n";
}
return 0;
}
コードは正常にコンパイルされますが、リンク時にのみエラーが発生します。コンパイルからの追加情報は次のとおりです。
chen@work:build$ make VERBOSE=1
/opt/local/bin/cmake -H/Users/chen/Code/clang -B/Users/chen/Code/clang/build --check-build-system CMakeFiles/Makefile.cmake 0
/opt/local/bin/cmake -E cmake_progress_start /Users/chen/Code/clang/build/CMakeFiles /Users/chen/Code/clang/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
cd /Users/chen/Code/clang/build && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /Users/chen/Code/clang /Users/chen/Code/clang /Users/chen/Code/clang/build /Users/chen/Code/clang/build /Users/chen/Code/clang/build/CMakeFiles/main.dir/DependInfo.cmake --color=
Dependee "/Users/chen/Code/clang/build/CMakeFiles/main.dir/DependInfo.cmake" is newer than depender "/Users/chen/Code/clang/build/CMakeFiles/main.dir/depend.internal".
Dependee "/Users/chen/Code/clang/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/chen/Code/clang/build/CMakeFiles/main.dir/depend.internal".
Scanning dependencies of target main
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
/opt/local/bin/cmake -E cmake_progress_report /Users/chen/Code/clang/build/CMakeFiles 1
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/usr/bin/clang++ -arch x86_64 -I/Users/chen/Code/clang -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Headers -I/Users/chen/Code/clang/Utilities/includes -std=c++11 -stdlib=libc++ -o CMakeFiles/main.dir/main.cpp.o -c /Users/chen/Code/clang/main.cpp
一方、正常にコンパイルされるマシンでは、文字通り libc++ の速度を「見る」ことができます。Xcode で使用すると、非常に高速で、libc++ によるコード補完は驚くべきものです。
しかし、さらに楽しむ前に、この問題の真相を突き止めたいと思います...