【发布时间】:2021-07-17 09:06:10
【问题描述】:
我正在使用 std::atomic 和 std::thread 支持在 Windows 上编译 GCC。 我在这里使用 mingw:http://winlibs.com/
我正在用这个命令构建:
g++.exe @CMakeFiles/StrFormatsJSONTest.dir/includes_CXX.rsp -latomic -lglu32 -lopengl32 -D_WIN32_WINNT=0x600 -DWINVER=0x600 -D_WIN32_LEAN_AND_MEAN=1 -g -std=gnu++2a -o main.cpp.obj -c main.cpp
但是,当使用#include <atomic> 时会出现以下错误:
[build] c:\utils\bin\mingw32\include\c++\10.3.0\ext\atomicity.h:83:9: error: '__gthread_active_p' was not declared in this scope
[build] 83 | if (__gthread_active_p())
如果我手动定义函数,我会得到一个多重定义错误(很明显它在项目中不知何故)。
我正在使用以下线程:
find_package( Threads )
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
我包括latomic 使用:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -latomic -lglu32 -lopengl32 -D_WIN32_WINNT=0x600 -DWINVER=0x600 -D_WIN32_LEAN_AND_MEAN=1 -D__GTHREADS=1")
^ 之所以这样,是因为我在项目中的所有目标中都需要它。
库声明如果 GTHREADS 宏为 1,则该函数应该存在:
很明显,这就是错误所在:
当我在#include <atomic> 之前添加定义(弱链接)时,它可以工作......但我遇到其他错误,例如:
error: '__gthread_once_t' does not name a type; did you mean '__gthread_active_p'?
出于某种原因,GCC 不包括以下任何一项:
- gthr-default.h
- gthr-posix.h
- ghr-single.h
【问题讨论】: