tags:

views:

140

answers:

2

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?

+2  A: 

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

usta
sorry how? i dont understand like this? std namespace :: boost?
using namespace boost?
No, it's not something to be changed in code. The -lXXX flags need to be added to your makefile.
usta
You need to find out how to link to 3rd party libraries in netbeans. I'm afraid I can't help you with that, as I have never worked with netbeans.
usta
This is the correct answer, @algorithms you should accept it and ask a separate question specific to your IDE if you do not understand how to configure it.
Sam Miller
+3  A: 

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.

Kornel Kisielewicz
i am using netbeans in ubuntu can you tell me how do it?please
Search in `Configuration Properties -> Linker -> Libraries`
Kornel Kisielewicz
@Komel i can't find configuration Properties sorry
please help i can't find where i should link Boost.system and BoostThread libraries
@algorithms, search around the menus. I neither have used nor have Netbeans installed, so I can't help you.
Kornel Kisielewicz
@Kornel Kisielewicz I don't think linking to Boost.Thread is necessary, Asio does not use Boost.Thread IIRC, but linking to pthread will be needed.
usta
@usta, true, corrected.
Kornel Kisielewicz