Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 关于推进asio的问题_C++_Boost Asio - Fatal编程技术网

C++ 关于推进asio的问题

C++ 关于推进asio的问题,c++,boost-asio,C++,Boost Asio,我有以下代码 #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,

我有以下代码

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

请帮助了解发生了什么?

您需要链接Boost.System库:-lboost\u系统
您还需要链接pthreads lib:-lpthread

问题不在代码中,问题在于编译器(实际上是链接器)的设置。您需要链接到Boost.System和pthread库。通常通过将
-lboost\u system
-lpthread
传递到Makefile或收藏夹IDE中的链接器选项来完成。您需要右键单击项目根文件夹并选择属性

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


如果在您尚未编译这些库的源代码之后找不到所需的文件。请查看boost tar软件包中包含的入门文档。

以供将来有相同问题的人参考:
在NETBeBeS中,右击项目--> Projt+C++编译器,在底部,在-LoBooSTyStor系统选项中有一个“传统参数”选项。注意:-必须定义Boost_系统,否则会出现错误

对不起,怎么做?我这样不明白?std名称空间::boost?不,它不是代码中可以更改的东西。需要将-lXXX标志添加到您的makefile中。您需要了解如何链接到netbeans中的第三方库。恐怕我帮不了你,因为我从未使用过netbeans。这是正确的答案,@algorithms如果您不了解如何配置它,您应该接受它,并针对您的IDE提出一个单独的问题。我正在ubuntu中使用netbeans。您能告诉我如何做到吗?请在
配置属性->链接器->库中搜索
@Komel我找不到配置属性,请帮助我找不到我的位置应该链接Boost.system和BoostThreadlibraries@algorithms,在菜单中搜索。我既没有使用也没有安装Netbeans,所以我帮不了你。
/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)