I'm trying to compile the following program with boost/asio.
#include <boost/asio.hpp>
int main(){
boost::asio::io_service ioservice;
return 0;
}
But I'm getting the following linker errors
C:\Users\...\ccsKX5WE.o:myprogram.cpp:(.text+0x136)undefined reference to `boost::system::generic_category()'
C:\Users\...\ccsKX5WE.o:myprogram.cpp:(.text+0x140)undefined reference to `boost::system::generic_category()'
C:/mingw/bin/.../ld.exe: C:\Users\...\ccsKx5WE.o: bad reloc address 0xe in section `.text$_|N5boost6system14error_categoryD2Ev]'
collect2.exe@ error: ld return 1 exit status
I used mingw as such:
g++ -IC:\boost\boost_1_59_0 -o myprogram.exe -LC:\boost\boost_1_59_0\stage\lib -lboost_system-mgw48-1_59 myprogram.cpp
I've used all the different versions of libboost_systems flags such as lboost_system-mgw48-1_59.a lboost_system-mgw48-mt-1_59.a etc and all together but nothing worked.
What might be causing this problem?
There are two problems with the command.
First, as πάντα ῥεῖ mentioned in the comments, the -lboost_system-mgw48-1_59 flag has to be after the object files.
Secondly, since I was using windows, I needed to add -lwsock32 as well.
g++ -IC:\boost\boost_1_59_0 myprogram.cpp -o myprogram.exe - LC:\boost\boost_1_59_0\stage\lib -lboost_system-mgw48-1_59 –lwsock32
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.