0

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?

Sam Miller
24.3k4 gold badges70 silver badges91 bronze badges
asked Sep 4, 2010 at 9:59

4 Answers 4

6

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.

answered Sep 4, 2010 at 10:16
Sign up to request clarification or add additional context in comments.

6 Comments

i am using netbeans in ubuntu can you tell me how do it?please
Search in Configuration Properties -> Linker -> Libraries
@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.
|
2

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

answered Sep 4, 2010 at 10:10

4 Comments

sorry how? i dont understand like this? std namespace :: boost?
No, it's not something to be changed in code. The -lXXX flags need to be added to your makefile.
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.
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.
0

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.

answered Dec 13, 2010 at 21:30

Comments

0

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

answered May 16, 2011 at 8:55

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.