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

      1. <legend id='ZY2Ev'><style id='ZY2Ev'><dir id='ZY2Ev'><q id='ZY2Ev'></q></dir></style></legend>
      2. <tfoot id='ZY2Ev'></tfoot>

        • <bdo id='ZY2Ev'></bdo><ul id='ZY2Ev'></ul>

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

      3. C++/Boost:示例中的未定义符号?

        时间:2023-09-17
          • <bdo id='ExDEJ'></bdo><ul id='ExDEJ'></ul>

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

            <tfoot id='ExDEJ'></tfoot>
            • <small id='ExDEJ'></small><noframes id='ExDEJ'>

                <legend id='ExDEJ'><style id='ExDEJ'><dir id='ExDEJ'><q id='ExDEJ'></q></dir></style></legend>
                  <tbody id='ExDEJ'></tbody>
                • 本文介绍了C++/Boost:示例中的未定义符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我试图编译的例子来自:http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html(聊天例子)

                  这是我用来制作它的:

                  <预><代码>>>>g++ chat_client.cpp chat_message.hpp>>>g++ chat_server.cpp chat_message.hpp

                  这是终端输出的内容:

                  % g++ chat_client.cpp chat_message.hpp在 chat_client.cpp:17 包含的文件中:chat_message.hpp:在成员函数‘void chat_message::encode_header()’中:chat_message.hpp:84: 警告:格式%4d"需要类型int",但参数 3 的类型为size_t"ld:警告:在 chat_message.hpp 中,文件是为不受支持的文件格式构建的,这不是所链接的体系结构 (x86_64)未定义符号:boost::system::generic_category()",引用自:__static_initialization_and_destruction_0(int, int)in cctJA2c1.o__static_initialization_and_destruction_0(int, int)in cctJA2c1.oboost::thread::start_thread()",引用自:boost::thread::thread, boost::_bi::list1>>>(boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >, boost::disable_if, boost::_bi::list1, boost::_bi::list1>>>在cctJA2c1.o中"vtable for boost::detail::thread_data_base",引用自:boost::detail::thread_data_base::thread_data_base() 在 cctJA2c1.oboost::thread::~thread()",引用自:_main 在 cctJA2c1.o_main 在 cctJA2c1.oboost::detail::thread_data_base::~thread_data_base()",引用自:boost::detail::thread_data, boost::_bi::list1>>>::~thread_data() 在 cctJA2c1.o 中boost::detail::thread_data, boost::_bi::list1>>>::~thread_data() 在 cctJA2c1.o 中boost::system::system_category()",引用自:cctJA2c1.o 中的 boost::system::get_system_category()cctJA2c1.o 中的 boost::system::error_code::error_code()__static_initialization_and_destruction_0(int, int)in cctJA2c1.old:未找到符号collect2: ld 返回 1 个退出状态

                  • Boost 安装正确.我有另一个应用,它使用了一些 boosts 位功能.

                  更新:这是我正在使用的当前命令:

                  % g++ chat_client.cpp chat_message.hpp -lboost_asio -lboost_thread -o client -L/opt/local/lib/

                  说它找不到 -lboost_asio

                  我查看了 opt/local/lib(安装了 boost 的地方),但我没有看到任何 libboost_asio.so 或类似的东西 =

                  解决方案

                  您需要提供 g++ boost 库以与 usins -l 选项链接.我快速浏览了这个示例,并猜测您肯定需要 thread 库.您可以使用

                  链接它

                  g++ source.cpp -o 可执行文件 -lboost_thread

                  你也可能需要使用

                  的 boost_system 库

                  g++ source.cpp -o 可执行文件 -lboost_thread -lboost_system

                  The example I'm trying to compile is from: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html (the chat example)

                  Here is what I'm using to make it:

                  >>>    g++ chat_client.cpp chat_message.hpp
                  >>>    g++ chat_server.cpp chat_message.hpp
                  

                  This is what the terminal outputs:

                  % g++ chat_client.cpp chat_message.hpp
                  In file included from chat_client.cpp:17:
                  chat_message.hpp: In member function ‘void chat_message::encode_header()’:
                  chat_message.hpp:84: warning: format ‘%4d’ expects type ‘int’, but argument 3 has type ‘size_t’
                  ld: warning: in chat_message.hpp, file was built for unsupported file format which is not the architecture being linked (x86_64)
                  Undefined symbols:
                    "boost::system::generic_category()", referenced from:
                        __static_initialization_and_destruction_0(int, int)in cctJA2c1.o
                        __static_initialization_and_destruction_0(int, int)in cctJA2c1.o
                    "boost::thread::start_thread()", referenced from:
                        boost::thread::thread<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >(boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >, boost::disable_if<boost::is_convertible<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >&, boost::detail::thread_move_t<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > > >, boost::thread::dummy*>::type)in cctJA2c1.o
                    "boost::thread::join()", referenced from:
                        _main in cctJA2c1.o
                    "typeinfo for boost::detail::thread_data_base", referenced from:
                        typeinfo for boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >in cctJA2c1.o
                    "vtable for boost::detail::thread_data_base", referenced from:
                        boost::detail::thread_data_base::thread_data_base()in cctJA2c1.o
                    "boost::thread::~thread()", referenced from:
                        _main in cctJA2c1.o
                        _main in cctJA2c1.o
                    "boost::detail::thread_data_base::~thread_data_base()", referenced from:
                        boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::~thread_data()in cctJA2c1.o
                        boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::~thread_data()in cctJA2c1.o
                    "boost::system::system_category()", referenced from:
                        boost::system::get_system_category()     in cctJA2c1.o
                        boost::system::error_code::error_code()in cctJA2c1.o
                        __static_initialization_and_destruction_0(int, int)in cctJA2c1.o
                  ld: symbol(s) not found
                  collect2: ld returned 1 exit status
                  

                  • Boost is installed correctly. I have another app that uses a couple of boosts bit features.

                  UPDATE: this is the current command I'm using:

                  % g++ chat_client.cpp chat_message.hpp -lboost_asio -lboost_thread -o client -L/opt/local/lib/
                  

                  says it can't find -lboost_asio

                  I looked in opt/local/lib (where boost is installed) and I don't see any libboost_asio.so or anything like that =

                  解决方案

                  You need to provide g++ boost libraries to link with usins -l option. I have a quick look on this examples and guess that you definitly need thread library. You can link with it using

                  g++ source.cpp -o executable -lboost_thread 
                  

                  Also you may need with boost_system library using

                  g++ source.cpp -o executable -lboost_thread -lboost_system
                  

                  这篇关于C++/Boost:示例中的未定义符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:处理多个客户端的单个 TCP/IP 服务器(在 C++ 中)? 下一篇:字节序何时成为一个因素?

                  相关文章

                  最新文章

                • <legend id='lyda3'><style id='lyda3'><dir id='lyda3'><q id='lyda3'></q></dir></style></legend>

                • <tfoot id='lyda3'></tfoot>

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

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

                      • <bdo id='lyda3'></bdo><ul id='lyda3'></ul>