关于boost asio的问题

发布于 2024-09-17 00:00:06 字数 2998 浏览 4 评论 0原文

我有以下代码

#include <boost/date_time/posix_time/posix_time.hpp>

#include <iostream>
#include <boost/asio.hpp>
using namespace std;
int main(int argc,char *argv[]) {

    boost::asio::io_service io;
    boost::asio::deadline_timer t(io,boost::posix_time::seconds(5));
    t.wait();
    std::cout<<" hello world\n";

    return 0;
}

,但我有以下错误列表,

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/david/NetBeansProjects/Boost'
/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/boost
make[2]: Entering directory `/home/david/NetBeansProjects/Boost'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++    -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++     -o dist/Debug/GNU-Linux-x86/boost build/Debug/GNU-Linux-x86/main.o  
build/Debug/GNU-Linux-x86/main.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:205: undefined reference to `boost::system::get_system_category()'
/usr/include/boost/system/error_code.hpp:206: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:211: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:212: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:213: undefined reference to `boost::system::get_system_category()'
build/Debug/GNU-Linux-x86/main.o: In function `error_code':
/usr/include/boost/system/error_code.hpp:312: undefined reference to `boost::system::get_system_category()'
build/Debug/GNU-Linux-x86/main.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost/asio/error.hpp:218: undefined reference to `boost::system::get_system_category()'
build/Debug/GNU-Linux-x86/main.o: In function `~posix_thread':
/usr/include/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach'
build/Debug/GNU-Linux-x86/main.o: In function `boost::asio::detail::posix_thread::join()':
/usr/include/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join'
build/Debug/GNU-Linux-x86/main.o: In function `~posix_tss_ptr':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete'
build/Debug/GNU-Linux-x86/main.o: In function `posix_tss_ptr':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/boost] Error 1
make[2]: Leaving directory `/home/david/NetBeansProjects/Boost'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/david/NetBeansProjects/Boost'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 5s)

请帮忙发生了什么?

i have following code

#include <boost/date_time/posix_time/posix_time.hpp>

#include <iostream>
#include <boost/asio.hpp>
using namespace std;
int main(int argc,char *argv[]) {

    boost::asio::io_service io;
    boost::asio::deadline_timer t(io,boost::posix_time::seconds(5));
    t.wait();
    std::cout<<" hello world\n";

    return 0;
}

but i have following error list

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/david/NetBeansProjects/Boost'
/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/boost
make[2]: Entering directory `/home/david/NetBeansProjects/Boost'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++    -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++     -o dist/Debug/GNU-Linux-x86/boost build/Debug/GNU-Linux-x86/main.o  
build/Debug/GNU-Linux-x86/main.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:205: undefined reference to `boost::system::get_system_category()'
/usr/include/boost/system/error_code.hpp:206: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:211: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:212: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:213: undefined reference to `boost::system::get_system_category()'
build/Debug/GNU-Linux-x86/main.o: In function `error_code':
/usr/include/boost/system/error_code.hpp:312: undefined reference to `boost::system::get_system_category()'
build/Debug/GNU-Linux-x86/main.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost/asio/error.hpp:218: undefined reference to `boost::system::get_system_category()'
build/Debug/GNU-Linux-x86/main.o: In function `~posix_thread':
/usr/include/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach'
build/Debug/GNU-Linux-x86/main.o: In function `boost::asio::detail::posix_thread::join()':
/usr/include/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join'
build/Debug/GNU-Linux-x86/main.o: In function `~posix_tss_ptr':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete'
build/Debug/GNU-Linux-x86/main.o: In function `posix_tss_ptr':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/boost] Error 1
make[2]: Leaving directory `/home/david/NetBeansProjects/Boost'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/david/NetBeansProjects/Boost'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 5s)

pleas help what is happaned?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

尴尬癌患者 2024-09-24 00:00:06

问题不在于您的代码,问题在于编译器(实际上是链接器)的设置。您需要链接到 Boost.System 和 pthread 库。通常,这是通过将 -lboost_system-lpthread 传递到 Makefile 或最喜欢的 IDE 中的链接器选项来完成的。

The problem is not in your code, the problem is in the settings of the compiler (actually linker). You need to link to the Boost.System and pthread libraries. Usually it's done by passing -lboost_system, -lpthread to the linker options in your Makefile, or favorite IDE.

离笑几人歌 2024-09-24 00:00:06

您需要链接Boost.System库:-lboost_system
您还需要链接 pthreads lib:-lpthread

You need to link with the Boost.System library: -lboost_system
Also you need to link with pthreads lib: -lpthread

别念他 2024-09-24 00:00:06

您需要右键单击项目根文件夹并选择属性。

从那里,您需要在左侧窗格中选择“链接器”,然后“库”选项字段就在那里。您需要浏览系统,直到找到 libboost_system.a 二进制文件。通常位于 /usr/local/lib。

如果您找不到所需的文件,则可能尚未编译这些库的源代码。查看 http://ubuntuforums.org/showthread.php?t=1180792 或boost tar 包中包含入门文档。

You need to right click your project root folder and select properties.

From there, you need to select 'Linker' in the left pane and the 'Libraries' option field is there. You need to browse your system till you find the libboost_system.a binary. Usually at /usr/local/lib.

If you cant find the file you are after you may not have compiled the source for those libraries yet. Check out either http://ubuntuforums.org/showthread.php?t=1180792 or the getting started documentation included in the boost tar package.

被翻牌 2024-09-24 00:00:06

供以后遇到同样问题的人参考:
在netbeans中右键单击项目-->属性-> C++ 编译器,底部有一个用于在 -lboost_system 选项中传递“附加参数”的选项。注意:必须定义 -lboost_system 否则会出现错误

For future reference to anyone with the same problem:
In netbeans right click the project -->Properties -> C++ Compiler and at the bottom there's an option for "Aditional arguments" pass in the -lboost_system option. Note: -lboost_system must be defined or you'll get errors

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文