[英]MSVC project missing “__popcountdi2” when linking against GCC-built static library
I have a windows executable project that links against a static library (.lib) built with GCC 6 (MinGW). 我有一个Windows可执行项目,该项目链接到使用GCC 6(MinGW)构建的静态库(.lib)。 The following error occurs during compilation: 编译期间发生以下错误:
LNK2019 unresolved external symbol __popcountdi2 referenced in function ...
The symbol is linked in as a result of using a GCC built-in function __builtin_popcount()
, which resides in libgcc. 通过使用驻留在libgcc中的GCC内置函数__builtin_popcount()
来链接该符号。 However, despite adding -static-libgcc
as an argument to gcc, the problem still persists. 但是,尽管将-static-libgcc
添加为gcc的参数,但问题仍然存在。
Is there a way for my library (.lib) to contain parts of libgcc rather than requiring libgcc to be on the system for an executable to link against? 有没有一种方法可以让我的库(.lib)包含libgcc的某些部分,而不是要求libgcc位于系统上以链接可执行文件? Is some way around having to ship the library with libgcc? 是否需要通过libgcc来运送库?
__builtin_popcount()
is not the only built-in function that I'm currently using. __builtin_popcount()
不是我当前正在使用的唯一内置函数。 The library makes use of __builtin_bswap32()
, which doesn't seem to run into this issue. 该库使用了__builtin_bswap32()
,似乎没有遇到这个问题。
I'm using GCC 6.1.0. 我正在使用GCC 6.1.0。 Updated to 6.2.0; 更新到6.2.0; same issue. 同样的问题。
The issue was that on windows, MinGW (GCC) was not detecting the current CPU architecture properly when -march=native
was passed in. It was falling back to an architecture that did not support POPCNT as a native instruction (probably i686). 问题是在Windows上,当传入-march=native
时,MinGW(GCC)无法正确检测当前的CPU体系结构。它回退到了不支持POPCNT作为本机指令的体系结构(可能是i686)。 As a test, -mpopcnt
was added to the build and everything worked fine. 作为测试, -mpopcnt
被添加到构建中,并且一切正常。
The fix is to manually specify the architecture using -march=
. 解决方法是使用-march=
手动指定体系结构。
Furthermore: is this a bug with MingGW since the native architecture is not polled for properly? 此外:由于未正确轮询本机体系结构,这是否是MingGW的错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.