简体   繁体   中英

Undefined references when including boost library

I am trying to use boost's asio library, but I keep getting undefined references. I'm on Dev-Cpp on Windows, which is using the G++ compiler.

I installed boost using the installer from boostpro computing for Boost 1.42.0 [ link ]. Here is the code of the test program I am trying to make:

#include <boost/asio.hpp>
#include <iostream>

int main(void){
    std::cout << "Boost test." << std::endl;
}

My boost include headers are under /include and all the libs for boost are compiled and under /lib directly. There seems to be some library that's not being included, but I do not know what is. I've tried including a few likely ones but to no avail.

The kind of linker errors I'm getting are:

[Linker error] undefined reference to `boost::system::get_system_category()'
[Linker error] undefined reference to `boost::system::get_generic_category()' 
[Linker error] undefined reference to `boost::system::get_generic_category()' 
[Linker error] undefined reference to `boost::system::get_generic_category()' 
[Linker error] undefined reference to `boost::system::get_system_category()' 
[Linker error] undefined reference to `WSACleanup@0' 
[Linker error] undefined reference to `WSAStartup@8' 
[Linker error] undefined reference to `boost::system::get_system_category()' 
ld returned 1 exit status 
C:\Dev-Cpp\Projects\Boost Test\Makefile.win [Build Error]  [boostTest.exe] Error 1 

I've been trying to get boost to work for a while and would really appreciate any help on the matter. Thanks in advance.

I had this problem a few days ago when working with boost::asio. You need compile and link with the boost::system library.

I use netbeans so i typed '-lboost_system' in additional lines ! That was a mistake.

Additional lines are put before objects, and because of that i had the same error. Then i found out if i run from console and put -lboost_system at the VERY END everything works greate. At the end i found the right place to set in netbeans (in library not command section) and that field adds it at the end!

Remember, not only counts if you have the library in command ! THE POSITION does count :) Remember to put library at end and verify it :)

Work great:

g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS   -c -g -MMD -MP -MF async_client.o.d -o async_client.o async_client.cpp
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -o async_client async_client.o -lws2_32 -lboost_chrono -lboost_system -lboost_thread

Doesn't work:

g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS   -c -g -MMD -MP -MF async_client.o.d -o async_client.o async_client.cpp
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -lws2_32 -lboost_chrono -lboost_system -lboost_thread -o async_client async_client.o 

您必须链接到libboost_system.a和libboost_filesystem.a。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM