简体   繁体   English

使用MinGW的Boost编译错误

[英]Compiling error with boost with mingw

I'm trying to compile the following program with boost/asio. 我正在尝试使用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: 我这样使用mingw:

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. 我已经使用了所有不同版本的libboost_systems标志,例如lboost_system-mgw48-1_59.a lboost_system-mgw48-mt-1_59.a等,所有这些一起使用,但没有任何效果。

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. 首先,正如注释中提到的,-lboost_system-mgw48-1_59标志必须位于目标文件之后。

Secondly, since I was using windows, I needed to add -lwsock32 as well. 其次,由于我使用的是Windows,因此还需要添加-lwsock32。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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