微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Windows 上的 pthreads 链接问题 - 应该归咎于 gcc 还是 SystemC?

如何解决Windows 上的 pthreads 链接问题 - 应该归咎于 gcc 还是 SystemC?

嗨,

我最近遇到了一个无法解释的链接问题。

这是一个再简单不过的例子:

sc_main.cpp:

#include <systemc.h>

int sc_main (int argc,char* argv[])
{
  sc_start(SC_ZERO_TIME);
  return(0);
} 

我使用以下代码编译和链接,使用 winlibs-x86_64-posix-seh-gcc-10.2.0-mingw-w64-8.0.0-r7.7z

g++ -pthread main_sc.cpp -o main_sc.exe -s $(LDFLAGS) -I$(SYstemC_HOME)/include -L$(SYstemC_HOME)/lib-mingw64 -lsystemc

现在,因为我的目标是 Win64,并且我想制作一个不依赖 MinGW-64 运行时库的可执行文件,所以我一直在研究许多可能的设置:

Option 1 - LDFLAGS := -static
Option 2 - LDFLAGS := -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
Option 3 - LDFLAGS := -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lpthread -Wl,-Bdynamic -Wl,--no-whole-archive

在这一点上,有时可以,有时不可以,具体取决于我使用的 SystemC 版本:

SytemC 2.3.2 + Option 1 : fine
SytemC 2.3.3 + Option 1 : libsystemc.a(sc_prim_channel.o):sc_prim_channel.cpp:(.text+0x44): undefined reference to `__imp_pthread_mutex_unlock'
                          libsystemc.a(sc_prim_channel.o):sc_prim_channel.cpp:(.text$_ZN7sc_core13sc_host_mutex6unlockEv[_ZN7sc_core13sc_host_mutex6unlockEv]+0xa): undefined reference to `__imp_pthread_mutex_unlock'
                          libsystemc.a(sc_prim_channel.o):sc_prim_channel.cpp:(.text$_ZN7sc_core17sc_host_semaphore7trywaitEv[_ZN7sc_core17sc_host_semaphore7trywaitEv]+0x2f): undefined reference to `__imp_pthread_mutex_unlock'

但是

SytemC 2.3.2 + Option 2 or 3 : fine
SytemC 2.3.3 + Option 2 or 3 : libpthread.dll.a(d000077.o):(.text+0x0): multiple deFinition of `pthread_mutex_unlock' ; mingw-w64-v8.0.0/mingw-w64-libraries/winpthreads/src/mutex.c:207: first defined here

请注意,我使用的工具链基于 gcc 10.2.0,但这并不相关。我只使用了这个工具链,因为它基于最新的 MinGW 库 (8.0.0)

事实上,我已经基于相同的 MinGW 8.0.0 库和 gcc 6.3.0 生成了我自己的(交叉编译)工具链(在 linux 上运行),并且我看到了完全相同的结果。>

知道发生了什么吗?我做错了什么吗?我不太确定这个问题是否与 SystemC 或 GCC/winpthreads 有关,但我很想认为 SystemC 可以被免除。 那么谁该受到责备,是否有解决方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。