2

我仍在为 libc++ 和 boost 苦苦挣扎。

我在这里用 libc++ 编译了 boost: 如何用 clang++/libc++ 编译/链接 Boost?

现在我在我的一台机器上看到了这个编译错误,而另一台机器用确切的代码编译得很好。它们都具有相同的编译器版本,环境变量也相同。

这是错误:

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

但在我进一步享受之前,我真的很想深入了解这个......

4

1 回答 1

1

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

于 2012-04-28T21:10:54.317 回答