首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在clang++ (Windows)中使用boost/thread有问题

在clang++ (Windows)中使用boost/thread有问题
EN

Stack Overflow用户
提问于 2015-05-02 22:43:05
回答 2查看 1.8K关注 0票数 15

我正在尝试使用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);
                                            ^
EN

回答 2

Stack Overflow用户

发布于 2015-05-20 18:07:56

有类似的问题,并使用boost_system参数标志修复了它。试试这个:

clang++ test.cpp -lboost_thread -lboost_system

这是我的点击信息:

~$clang++ --version
  clang version 3.2 (trunk 163783)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix

这也适用于g++:

~$g++ --version
  g++ (GCC) 4.9.2
  Copyright (C) 2014 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

另外,请看这里的这些线程:

Compiling C++ source file using Boost.Thread

https://stackoverflow.com/questions/19017335/cmake-force-use-of-non-mt-boost-libraries

票数 4
EN

Stack Overflow用户

发布于 2015-11-09 05:33:23

我刚刚在windows下的一个项目上运行include-what-you-use时遇到了这个问题。

这个程序用QT创建器编译得很好,但是为了让它用include-what-you-use进行编译,我必须将-DBOOST_USE_WINDOWS_H添加到编译中,并用#ifndef _APISETLIBLOADER_...#endif阻塞'thread_primitives.hpp‘中第220行的extern "C"

至少我知道这是安全的,但完全不清楚为什么它不能正常工作。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30003585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档