用libc ++编译的boost连接

时间:2012-04-28 01:12:40

标签: macos clang libc++

我仍在努力使用libc ++和boost。

我在这里使用libc ++编译了boost: How to compile/link Boost with clang++/libc++?

现在我在我的一台机器上看到这个编译错误,而另一台机器编译完全正确的代码。它们都具有相同的编译器版本,环境变量也是相同的。

这是错误:

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;
}

代码编译正常,但链接时只会出错。这是来自compile的额外信息:

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 ++完成代码非常棒。

但在我进一步享受之前,我真的想深究这个......

1 个答案:

答案 0 :(得分:1)

我刚刚发现了我的问题。这是由于Boost没有正确编译,因为libiconv在我的其他机器中无法被bjam识别。我想它不被识别的原因可能是因为我安装了macport。在我卸载了所有的macport东西后,bjam可以立即识别libiconv并在libc ++下正确构建boost,除了信号,但没关系。