【发布时间】:2015-07-12 06:31:31
【问题描述】:
我正在尝试使用 clang++ 在 Windows 上使用 Boost.Thread。
在包含 boost/thread.hpp 时,我收到以下编译错误:
使用-DBOOST_USE_WINDOWS_H:
In file included from D:/env/boost/boost_1_58_0\boost/thread.hpp:13:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread.hpp:12:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread_only.hpp:15:
In file included from D:/env/boost/boost_1_58_0\boost/thread/win32/thread_data.hpp:11:
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:223:67: error: conflicting types for 'GetProcAddress'
__declspec(dllimport) detail::farproc_t __stdcall GetProcAddress(void *, const char *);
^
/mingw/include\winbase.h:1675:27: note: previous declaration is here
WINBASEAPI FARPROC WINAPI GetProcAddress(HINSTANCE,LPCSTR);
^
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread_only.hpp:15:
In file included from D:/env/boost/boost_1_58_0\boost/thread/win32/thread_data.hpp:11:
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:223:67: warning: redeclaration of 'GetProcAddress' should not add 'dllimport' attribute [-Wdll-attribute-on-redeclaration]
__declspec(dllimport) detail::farproc_t __stdcall GetProcAddress(void *, const char *);
^
/mingw/include\winbase.h:1675:27: note: previous declaration is here
WINBASEAPI FARPROC WINAPI GetProcAddress(HINSTANCE,LPCSTR);
^
In file included from D:\Documents\solid\solid\Solid.clion\src\Concurrent\tests\ThreadPoolTests.cpp:11:
In file included from D:/env/boost/boost_1_58_0\boost/thread.hpp:13:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread.hpp:12:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread_only.hpp:15:
In file included from D:/env/boost/boost_1_58_0\boost/thread/win32/thread_data.hpp:11:
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:225:56: error: functions that differ only in their return type cannot be overloaded
__declspec(dllimport) void * __stdcall GetModuleHandleA(const char *);
^
/mingw/include\winbase.h:1648:27: note: previous declaration is here
WINBASEAPI HMODULE WINAPI GetModuleHandleA(LPCSTR);
^
In file included from D:/env/boost/boost_1_58_0\boost/thread.hpp:13:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread.hpp:12:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread_only.hpp:15:
In file included from D:/env/boost/boost_1_58_0\boost/thread/win32/thread_data.hpp:11:
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:225:56: warning: redeclaration of 'GetModuleHandleA' should not add 'dllimport' attribute [-Wdll-attribute-on-redeclaration]
__declspec(dllimport) void * __stdcall GetModuleHandleA(const char *);
^
/mingw/include\winbase.h:1648:27: note: previous declaration is here
WINBASEAPI HMODULE WINAPI GetModuleHandleA(LPCSTR);
^
In file included from D:/env/boost/boost_1_58_0\boost/thread.hpp:13:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread.hpp:12:
In file included from D:/env/boost/boost_1_58_0\boost/thread/thread_only.hpp:15:
In file included from D:/env/boost/boost_1_58_0\boost/thread/win32/thread_data.hpp:11:
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:229:63: warning: redeclaration of 'GetTickCount' should not add 'dllimport' attribute [-Wdll-attribute-on-redeclaration]
__declspec(dllimport) unsigned long __stdcall GetTickCount();
^
/mingw/include\winbase.h:1758:25: note: previous declaration is here
WINBASEAPI DWORD WINAPI GetTickCount(VOID);
^
不使用-DBOOST_USE_WINDOWS_H:
mingw32-make.exe[1]: *** [src/Core/CMakeFiles/Core.dir/all] Error 2
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1358:26: error: conflicting types for 'CreateEventA'
WINBASEAPI HANDLE WINAPI CreateEventA(LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR);
^
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:166:55: note: previous declaration is here
__declspec(dllimport) void* __stdcall CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1386:26: error: conflicting types for 'CreateMutexA'
WINBASEAPI HANDLE WINAPI CreateMutexA(LPSECURITY_ATTRIBUTES,BOOL,LPCSTR);
^
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:164:55: note: previous declaration is here
__declspec(dllimport) void* __stdcall CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1412:26: error: conflicting types for 'CreateSemaphoreA'
WINBASEAPI HANDLE WINAPI CreateSemaphoreA(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCSTR);
^
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:165:55: note: previous declaration is here
__declspec(dllimport) void* __stdcall CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1492:24: error: conflicting types for 'FileTimeToLocalFileTime'
WINBASEAPI BOOL WINAPI FileTimeToLocalFileTime(CONST FILETIME *,LPFILETIME);
^
D:/env/boost/boost_1_58_0\boost/date_time/filetime_functions.hpp:58:45: note: previous declaration is here
__declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const FILETIME* lpFileTime, FILETIME* lpLocalFileTime);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1648:27: error: functions that differ only in their return type cannot be overloaded
WINBASEAPI HMODULE WINAPI GetModuleHandleA(LPCSTR);
^
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:225:56: note: previous declaration is here
__declspec(dllimport) void * __stdcall GetModuleHandleA(const char *);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1675:27: error: conflicting types for 'GetProcAddress'
WINBASEAPI FARPROC WINAPI GetProcAddress(HINSTANCE,LPCSTR);
^
D:/env/boost/boost_1_58_0\boost/thread/win32/thread_primitives.hpp:223:67: note: previous declaration is here
__declspec(dllimport) detail::farproc_t __stdcall GetProcAddress(void *, const char *);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1729:24: error: conflicting types for 'GetSystemTime'
WINBASEAPI VOID WINAPI GetSystemTime(LPSYSTEMTIME);
^
D:/env/boost/boost_1_58_0\boost/date_time/filetime_functions.hpp:59:46: note: previous declaration is here
__declspec(dllimport) void __stdcall GetSystemTime(SYSTEMTIME* lpSystemTime);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:1734:24: error: conflicting types for 'GetSystemTimeAsFileTime'
WINBASEAPI void WINAPI GetSystemTimeAsFileTime(LPFILETIME);
^
D:/env/boost/boost_1_58_0\boost/date_time/filetime_functions.hpp:57:46: note: previous declaration is here
__declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(FILETIME* lpFileTime);
^
In file included from /mingw/include\windows.h:50:
/mingw/include\winbase.h:2159:24: error: conflicting types for 'SystemTimeToFileTime'
WINBASEAPI BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME*,LPFILETIME);
^
D:/env/boost/boost_1_58_0\boost/date_time/filetime_functions.hpp:60:45: note: previous declaration is here
__declspec(dllimport) int __stdcall SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime, FILETIME* lpFileTime);
^
【问题讨论】:
-
抱歉,如果这看起来很挑剔:如果您使用的是 clang++,那么您没有使用 MinGW。可能是 clang 人采用了从 MinGW.org 获取的标头,用于他们的编译器,但这并不能使其成为 MinGW 编译器,(MinGW.org 不支持 )。这是一个铿锵的问题;这不是 MinGW 问题。
-
您正在使用 MinGW 头文件编译 Win32 代码。那是行不通的。
-
你能说得更具体点吗?错误似乎来自boost的标题,那么您指的是哪个win32代码?
-
你的 mingw 版本是什么?我有 4.8.2 和 4.9.1(虽然是 GCC),但它们都没有在
winbase.h上声明这些函数。 作为实验,您可以尝试在您的此标头版本上注释第 1648、1675 和 1758 行(因为无法使用定义或标志来停用此功能,无论是在winbase.h还是在 @ 987654325@)。在thread_primitives上评论类似的行也可以。 -
@CássioRenan 好吧,这实际上似乎解决了问题! (IDK,如果以后会引起更多问题,但现在一切都很好)我不能奖励你,因为这不是一个答案(如果你仍然可以尝试将它作为答案发布)
标签: c++ boost boost-thread clang++