[英]mingw g++ is unable to link with libraries
I'm trying to use X86_64-w64-mingw32-g++
(packaged in Archlinux's MingW package) to cross compile some C++ code into an Windows executable, however I'm having trouble getting past some issues. 我正在尝试使用X86_64-w64-mingw32-g++
(打包在Archlinux的MingW软件包中)将一些C ++代码交叉编译为Windows可执行文件,但是我很难克服一些问题。
I'm calling 我打电话
x86_64-w64-mingw32-g++ -o build_win/asm build_win/asm.o build_win/asm_lib.o build_win/socket_boost.o -I../extra/etc -fopenmp -lrt -std=c++11 -g -lboost_system -lboost_serialization
from a makefile, but I get thrown the errors: 从makefile,但我抛出错误:
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lrt
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_system
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_serialization
This works fine with native g++, so exactly do I have to change for mingw to compile? 这在本机g ++上可以正常工作,因此我是否必须更改才能使mingw进行编译?
EDIT: I have mingw-w64-boost
package installed, which includes boost libraries pre-compiled and ready to be linked. 编辑:我安装了mingw-w64-boost
软件包,其中包括预编译并准备好进行链接的boost库。 However, it seems the naming convention is a bit different, and -lboost_system
for example becomes -llibboost_system-mt
(not exactly sure what the -mt suffix entails). 但是,似乎命名约定有点不同,例如, -lboost_system
变为-llibboost_system-mt
(不确定-mt后缀的含义)。
Problem is I can't find the mingw counterpart for -lrt
. 问题是我找不到-lrt
的mingw副本。 I've tried with both -lrtm
and -lrtutils
but in both cases I get: 我已经尝试使用-lrtm
和-lrtutils
但是在两种情况下我都得到了:
[...]
undefined reference to `__imp_getsockopt'
Are you sure that -lboost_system
and other libraries are present in the same directory as makefile ? 您确定-lboost_system
和其他库与makefile位于同一目录中吗?
If not
then please include -L
flag which indicates the location of your library. 如果not
那么请包括-L
标志,它指示您的磁带库的位置。
For example: 例如:
-L /path_openmp -fopenmp -L /path_boost_system/ -lboost_system -L /path_serialization -lboost_serialization
Moreover, you need not include -I
and -g
flag when creating an executable from .o
files. 此外,从.o
文件创建可执行文件时,无需包括-I
和-g
标志。 These are needed when you create .o
from .cpp
files. 从.cpp
文件创建.o
时,这些是必需的。
There is no rt
library on Windows. Windows上没有rt
库。
You are missing -lws2_32
. 您缺少-lws2_32
。
$ x86_64-w64-mingw32-nm -A /usr/x86_64-w64-mingw32/lib/*.a 2>/dev/null | grep getsockopt | grep " T "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.