I'm trying to build boost asio timer sample within Eclipse on Windows and I occurred following errors:
g++ "-LC:\\Boost\\lib" -o boost_sync_timer.exe "src\\boost_sync_timer.o" -lws2_32 -llibboost_system-vc140-mt-1_61 -llibboost_system-vc140-mt-s-1_61 -llibboost_system-vc140-sgd-1_61 -llibboost_system-vc140-s-1_61 -llibboost_system-vc140-mt-sgd-1_61 -llibboost_system-vc140-mt-gd-1_61 -lboost_system-vc140-mt-1_61 -lboost_system-vc140-mt-gd-1_61
src\boost_sync_timer.o: In function `_static_initialization_and_destruction_0':
C:/Boost/include/boost-1_61/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Boost/include/boost-1_61/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Boost/include/boost-1_61/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
src\boost_sync_timer.o: In function `ZN5boost6system10error_codeC1Ev':
C:/Boost/include/boost-1_61/boost/system/error_code.hpp:322: undefined reference to `boost::system::system_category()'
src\boost_sync_timer.o: In function `ZN5boost4asio5error19get_system_categoryEv':
C:/Boost/include/boost-1_61/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
collect2.exe: error: ld returned 1 exit status
There are already lots of similar issues posted but most of them are on Linux OS.(like undefined reference to boost::system::system_category() when compiling, -lboost_system should fix)
Although this post How to build boost::asio? is a similar issue, but its solution seems strange. My boost library is build with msvc-14.0(bjam --toolset=msvc-14.0 --build-type=complete architecture=x86 address-model=64 install). Should there be no difference no matter what compler to use while installing boost library?
As you can see, I import all "system" related libraries under "C:\Boost\lib", but there are still above errors! Any help? Thanks a lot!
Related
I am trying to follow some sqlite C++ tutorial to be able to access a database from within C++ code on Linux. sqlite3 is installed and working, but when I try to compile the example code given on the link (Create a Table) I get the following error:
g++ build/test.o -o bin/test -pthread -L lib
build/test.o: In function `main':
/home/alexander/Projects/Test/src/test.cpp:22: undefined reference to `sqlite3_open'
/home/alexander/Projects/Test/src/test.cpp:24: undefined reference to `sqlite3_errmsg'
/home/alexander/Projects/Test/src/test.cpp:39: undefined reference to `sqlite3_exec'
/home/alexander/Projects/Test/src/test.cpp:42: undefined reference to `sqlite3_free'
/home/alexander/Projects/Test/src/test.cpp:46: undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status
Do I need to install something else? Or do I need to set some paths?
I have no practice in compiling straight from the shell.
In CodeBlocks it is necessary to point the paths of the “sqlite3.h” header and the “libsqlite3.so” dll.
If the dll is not specified in Linker Settings, exactly the mentioned problem occurs.
I am trying to link libevent using g++ but am having trouble since I set libevent's install directory with the --prefix flag when configuring. To install libevent I downloaded the latest source, extracted it and ran the following commands in the directory
./configure --prefix=/home/tom/local --disable-shared && make
make install
After running these commands libevent successfully installs to the /home/tom/local folder. Now to test that I can use libevent I have downloaded the sample rot13 server with libevent that can be found towards the bottom of: http://www.wangafu.net/~nickm/libevent-book/01_intro.html
To compile I run the following command:
g++ -I=/home/tom/local/include rot13server.cpp -L/home/tom/local/lib
But I get the following compilation errors:
/tmp/cctwJY4k.o: In function `alloc_fd_state(event_base*, int)':
libevent.cc:(.text+0x9b): undefined reference to `event_new'
libevent.cc:(.text+0xec): undefined reference to `event_new'
libevent.cc:(.text+0x11a): undefined reference to `event_free'
/tmp/cctwJY4k.o: In function `free_fd_state(fd_state*)':
libevent.cc:(.text+0x1b6): undefined reference to `event_free'
libevent.cc:(.text+0x1c9): undefined reference to `event_free'
/tmp/cctwJY4k.o: In function `do_read(int, short, void*)':
libevent.cc:(.text+0x310): undefined reference to `event_add'
/tmp/cctwJY4k.o: In function `do_write(int, short, void*)':
libevent.cc:(.text+0x4da): undefined reference to `event_del'
/tmp/cctwJY4k.o: In function `do_accept(int, short, void*)':
libevent.cc:(.text+0x564): undefined reference to `evutil_make_socket_nonblocking'
libevent.cc:(.text+0x5da): undefined reference to `event_add'
/tmp/cctwJY4k.o: In function `run()':
libevent.cc:(.text+0x5f3): undefined reference to `event_base_new'
libevent.cc:(.text+0x63f): undefined reference to `evutil_make_socket_nonblocking'
libevent.cc:(.text+0x6d2): undefined reference to `event_new'
libevent.cc:(.text+0x6e7): undefined reference to `event_add'
libevent.cc:(.text+0x6f3): undefined reference to `event_base_dispatch'
collect2: error: ld returned 1 exit status
It seems like the compiler is finding the include files but not the object files.
I also tried configuring libevent without the --disable-shared option and then exported /home/tom/local/lib to the LD_LIBRARY_PATH but I still get the same error with the compile command:
g++ -I=/home/tom/local/include rot13server.cpp
Can anyone tell me what I am doing wrong?
Thanks
Can anyone tell me what I am doing wrong?
Just about everything.
The -I=/home/tom/local/include tells GCC to look in =/home/tom/local/include directory, which is unlikely to exist.
You want:
g++ -I/home/tom/local/include rot13server.cpp -c
g++ -L/home/tom/local/lib rot13server.o -levent -o rot13server
This question already has an answer here:
g++ and boost linker error on Ubuntu oneiric
(1 answer)
Closed 8 years ago.
folks!
I'm using ubuntu 12.04 and trying to compile a boost test program. I installed boost with
sudo apt-get install libboost-all-dev
an so, I don't know where i can find my libraries. I tried do compile that using
g++ -lboost_system -lboost_thread boost_test.cpp
thinking maybe to have some default path where ubuntu installed boost automatically, but it was wrong and I had the following:
/tmp/ccTKXzTR.o: In function
__static_initialization_and_destruction_0(int, int)':
boost_test.cpp:(.text+0xcc): undefined reference to
boost::system::generic_category()' boost_test.cpp:(.text+0xd8):
undefined reference to boost::system::generic_category()'
boost_test.cpp:(.text+0xe4): undefined reference to
boost::system::system_category()' /tmp/ccTKXzTR.o: In function
boost::system::error_code::error_code()':
boost_test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17):
undefined reference toboost::system::system_category()'
/tmp/ccTKXzTR.o: In function
boost::asio::error::get_system_category()':
boost_test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5):
undefined reference toboost::system::system_category()'
/tmp/ccTKXzTR.o: In function
boost::asio::detail::posix_tss_ptr_create(unsigned int&)':
boost_test.cpp:(.text._ZN5boost4asio6detail20posix_tss_ptr_createERj[_ZN5boost4asio6detail20posix_tss_ptr_createERj]+0x19):
undefined reference topthread_key_create' /tmp/ccTKXzTR.o: In
function
boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service,
boost::asio::detail::task_io_service::thread_info>::context>::~posix_tss_ptr()':
boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED5Ev]+0x15): undefined reference topthread_key_delete' /tmp/ccTKXzTR.o: In
function
boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl,
unsigned char>::context>::~posix_tss_ptr()':
boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED5Ev]+0x15):
undefined reference topthread_key_delete' collect2: error: ld
returned 1 exit status
Can someone help-me to figure out if my library is correctly installed and compile that?
I found out /usr/include/boost is the path to boost headers and /usr/lib contains all boost libraries i want to.
I Followed the guide for unix. http://www.boost.org/doc/libs/1_51_0/more/getting_started/unix-variants.html. It works fine on my mac. But on my VPS I seem to be having a few issues. I downloaded the latest build and ran bootstrap and b2 install and the example.cpp worked fine.
When I tired to compile the boost udp echo server - http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/example/echo/async_udp_echo_server.cpp
I get following error.
andrew#am:~/Documents/boostExamples/asyncUdpEchoServer$ c++ -I /usr/local/boost main.cpp -o udpEchoServer
/tmp/cczYAR1r.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x21e): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x228): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x232): undefined reference to `boost::system::system_category()'
/tmp/cczYAR1r.o: In function `boost::system::error_code::error_code()':
main.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x10): undefined reference to `boost::system::system_category()'
/tmp/cczYAR1r.o: In function `boost::asio::error::get_system_category()':
main.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x7): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
Any ideas what I need to do here? - I was sort if under the influence that you don't need to build boost.
The vps is running ubuntu server 11.10 but it seems to be a little cut down. I have installed build-essential.
You must link boost_system lib: -lboost_system. Also dont forget to specify lib directory if need.
I am trying to use mongodb for the first time in c++. I just installed the latest version on Ubuntu and also installed the lastest v2.0 c++ driver code. It compiled just fine using scons. In the c++ file the below is my include.
#include <client/dbclient.h>
So..I am assuming I have to make a ref to a boost library but I don't know how to do it.
make all
Building target: rtb
Invoking: GCC C++ Linker
g++ -L/usr/local/include/ -L/home/boost -L/home/cpp/mongo-cxx-driver-v2.0/mongo -lfcgi++ -o"rtb" ./src/rtb.o
./src/rtb.o: In function `__static_initialization_and_destruction_0':
/home/boost/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/home/boost/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/home/boost/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [rtb] Error 1
Add -lboost_system to your link line.