1. <tfoot id='j72ti'></tfoot>
    2. <legend id='j72ti'><style id='j72ti'><dir id='j72ti'><q id='j72ti'></q></dir></style></legend>
      • <bdo id='j72ti'></bdo><ul id='j72ti'></ul>

        <small id='j72ti'></small><noframes id='j72ti'>

        <i id='j72ti'><tr id='j72ti'><dt id='j72ti'><q id='j72ti'><span id='j72ti'><b id='j72ti'><form id='j72ti'><ins id='j72ti'></ins><ul id='j72ti'></ul><sub id='j72ti'></sub></form><legend id='j72ti'></legend><bdo id='j72ti'><pre id='j72ti'><center id='j72ti'></center></pre></bdo></b><th id='j72ti'></th></span></q></dt></tr></i><div id='j72ti'><tfoot id='j72ti'></tfoot><dl id='j72ti'><fieldset id='j72ti'></fieldset></dl></div>

        为什么不能在 c++0x 模式下使用 libc++ 链接这个 boost::program_options 示例?

        Why can#39;t clang with libc++ in c++0x mode link this boost::program_options example?(为什么不能在 c++0x 模式下使用 libc++ 链接这个 boost::program_options 示例?)
        <legend id='VeFGU'><style id='VeFGU'><dir id='VeFGU'><q id='VeFGU'></q></dir></style></legend>
      1. <tfoot id='VeFGU'></tfoot>
            <bdo id='VeFGU'></bdo><ul id='VeFGU'></ul>

              <i id='VeFGU'><tr id='VeFGU'><dt id='VeFGU'><q id='VeFGU'><span id='VeFGU'><b id='VeFGU'><form id='VeFGU'><ins id='VeFGU'></ins><ul id='VeFGU'></ul><sub id='VeFGU'></sub></form><legend id='VeFGU'></legend><bdo id='VeFGU'><pre id='VeFGU'><center id='VeFGU'></center></pre></bdo></b><th id='VeFGU'></th></span></q></dt></tr></i><div id='VeFGU'><tfoot id='VeFGU'></tfoot><dl id='VeFGU'><fieldset id='VeFGU'></fieldset></dl></div>

                  <tbody id='VeFGU'></tbody>

              • <small id='VeFGU'></small><noframes id='VeFGU'>

                1. 本文介绍了为什么不能在 c++0x 模式下使用 libc++ 链接这个 boost::program_options 示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为 boost::program_options 编译这个示例代码:http://svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp

                  Compiling this example code for boost::program_options: http://svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp

                  ...在 MacOS Lion (10.7.2) 上,使用安装了 MacPorts 的 boost-1.48.0:

                  ...on MacOS Lion (10.7.2), using boost-1.48.0 installed with MacPorts:

                  $ clang++ -v
                  Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
                  Target: x86_64-apple-darwin11.2.0
                  Thread model: posix
                  $ clang++ -std=c++0x --stdlib=libc++ -lc++ -I/opt/local/include -L/opt/local/lib -lboost_program_options first.cpp -o first
                  Undefined symbols for architecture x86_64:
                    "boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
                        _main in cc-6QQcwm.o
                    "boost::program_options::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, boost::program_options::options_description const&)", referenced from:
                        _main in cc-6QQcwm.o
                    "boost::program_options::abstract_variables_map::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
                        boost::program_options::variables_map::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in cc-6QQcwm.o
                    "boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>)", referenced from:
                        boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>) in cc-6QQcwm.o
                    "boost::program_options::detail::cmdline::cmdline(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&)", referenced from:
                        boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*) in cc-6QQcwm.o
                    "boost::program_options::to_internal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
                        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> > > > boost::program_options::to_internal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<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&) in cc-6QQcwm.o
                    "boost::program_options::invalid_option_value::invalid_option_value(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
                        void boost::program_options::validate<int, char>(boost::any&, 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&, int*, long) in cc-6QQcwm.o
                    "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 cc-6QQcwm.o
                    "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, 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) const", referenced from:
                        vtable for boost::program_options::typed_value<int, char> in cc-6QQcwm.o
                  ld: symbol(s) not found for architecture x86_64
                  clang: error: linker command failed with exit code 1 (use -v to see invocation)
                  

                  使用 MacPorts 安装的 g++4.7 编译/链接的相同代码:

                  The same code compiled/linked with g++4.7 installed with MacPorts:

                  $ g++-mp-4.7 -std=c++0x -I/opt/local/include -L/opt/local/lib -lboost_program_options -o first first.cpp
                  

                  ...工作正常.与在没有 libc++ 的情况下使用 clang 一样:

                  ... works fine. As does using clang without libc++:

                  clang++ -std=c++0x -I/opt/local/include -L/opt/local/lib -lboost_program_options first.cpp -o first
                  

                  怎么了?为什么 boost::program_options 和 libc++ 不能一起工作?

                  What's wrong? Why does boost::program_options and libc++ not work together?

                  推荐答案

                  您需要使用 clang++ -stdlib=libc++ 重建 boost.

                  You need to rebuild boost using clang++ -stdlib=libc++.

                  libc++ 与 gcc 的 libstdc++ 不是二进制兼容的(除了一些低级的东西,比如 operator new).例如,gcc 的 libstdc++ 中的 std::string 被引用计数,而在 libc++ 中它使用短字符串优化".如果您不小心在同一个程序中混合了这两个字符串(并将它们误认为是相同的数据结构),则不可避免地会导致运行时崩溃.

                  libc++ is not binary compatible with gcc's libstdc++ (except for some low level stuff such as operator new). For example the std::string in gcc's libstdc++ is refcounted, whereas in libc++ it uses the "short string optimization". If you were to accidentally mix these two strings in the same program (and mistake them for the same data structure), you would inevitably get a run time crash.

                  这起事故正是你的情况.

                  This accident is exactly what has occurred in your case.

                  为了把这个运行时崩溃变成链接时错误,libc++使用了一个叫做inline namespace的C++11语言特性来改变ABI>std::string 不会影响 std::stringAPI.也就是说,对你来说 std::string 看起来是一样的.但是对于链接器来说,std::string 被破坏了,就好像它在命名空间 std::__1 中一样.因此链接器知道 std::basic_stringstd::__1::basic_string 是两种不同的数据结构(前者来自 gcc 的 libstdc++,后者来自 libc++).

                  In order to turn this run time crash into a link time error, libc++ uses a C++11 language feature called inline namespace to change the ABI of std::string without impacting the API of std::string. That is, to you std::string looks the same. But to the linker, std::string is being mangled as if it is in namespace std::__1. Thus the linker knows that std::basic_string and std::__1::basic_string are two different data structures (the former coming from gcc's libstdc++ and the latter coming from libc++).

                  这篇关于为什么不能在 c++0x 模式下使用 libc++ 链接这个 boost::program_options 示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)
                  <i id='4zFan'><tr id='4zFan'><dt id='4zFan'><q id='4zFan'><span id='4zFan'><b id='4zFan'><form id='4zFan'><ins id='4zFan'></ins><ul id='4zFan'></ul><sub id='4zFan'></sub></form><legend id='4zFan'></legend><bdo id='4zFan'><pre id='4zFan'><center id='4zFan'></center></pre></bdo></b><th id='4zFan'></th></span></q></dt></tr></i><div id='4zFan'><tfoot id='4zFan'></tfoot><dl id='4zFan'><fieldset id='4zFan'></fieldset></dl></div>
                2. <tfoot id='4zFan'></tfoot>
                    <tbody id='4zFan'></tbody>

                  <small id='4zFan'></small><noframes id='4zFan'>

                  <legend id='4zFan'><style id='4zFan'><dir id='4zFan'><q id='4zFan'></q></dir></style></legend>

                        <bdo id='4zFan'></bdo><ul id='4zFan'></ul>