Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

boost usage w/clang on windows

39 views
Skip to first unread message

Mark

unread,
Feb 16, 2019, 11:20:30 PM2/16/19
to

I installed clang v9.0 on a windows 7 asset. I installed boost and compiled it as follows:

C:\Temp\boost_1_69_0>bootstrap.bat –toolset=clang
C:\Temp\boost_1_69_0> b2 -j8 toolset=clang address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --layout=versioned --build-type=complete stage


I'm trying to compile and run the following

#include <boost/thread.hpp>
#include <boost/chrono.hpp>
#include <iostream>

void wait(int seconds)
{
boost::this_thread::sleep_for(boost::chrono::seconds{seconds});
}

void thread()
{
for (int i = 0; i < 5; ++i)
{
wait(1);
std::cout << i << '\n';
}
}

int main()
{
boost::thread t{thread};
t.join();
}


Banging my head against a linker issue shown below. One incredibly confusing aspect with the output below is the Visual Studio 2017 Professional references. I'm not interested in using visual studio at all yet it appears Visual Studio 2017 runtime headers are being referenced. This is my first rodeo with clang on a Windows asset and wasn't anticipating this much pain. I suspect I'm not in the right forum but hopeful someone can help. Thoughts?


c:\eclipse-workspace\boost_thread>clang++ -DBOOST_USE_WINDOWS_H -DBOOST_HAS_THREADS -D_WIN32_WINNT=0x0601 "-IC:\\lib\\boost_1_69_0" "-LC:\\lib\\boost_1_69_0\\stage\\lib -boost_thread-clang9-mt-d-x64-1_69 -boost_system-clang9-mt-d-x64-1_69 -boost_chrono-clang9-mt-d-x64-1_69" "main.cpp" -std=c++14
In file included from main.cpp:1:
In file included from C:\\lib\\boost_1_69_0\boost/thread.hpp:13:
In file included from C:\\lib\\boost_1_69_0\boost/thread/thread.hpp:12:
In file included from C:\\lib\\boost_1_69_0\boost/thread/thread_only.hpp:15:
In file included from C:\\lib\\boost_1_69_0\boost/thread/win32/thread_data.hpp:10:
In file included from C:\\lib\\boost_1_69_0\boost/thread/thread_time.hpp:9:
In file included from C:\\lib\\boost_1_69_0\boost/date_time/time_clock.hpp:16:
C:\\lib\\boost_1_69_0\boost/date_time/c_time.hpp:101:23: warning: 'localtime' is deprecated: This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use
_CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
result = std::localtime(t);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\time.h:505:9: note: 'localtime' has been explicitly marked deprecated here
_CRT_INSECURE_DEPRECATE(localtime_s)
^
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:255:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
^
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:245:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
In file included from main.cpp:1:
In file included from C:\\lib\\boost_1_69_0\boost/thread.hpp:13:
In file included from C:\\lib\\boost_1_69_0\boost/thread/thread.hpp:12:
In file included from C:\\lib\\boost_1_69_0\boost/thread/thread_only.hpp:15:
In file included from C:\\lib\\boost_1_69_0\boost/thread/win32/thread_data.hpp:10:
In file included from C:\\lib\\boost_1_69_0\boost/thread/thread_time.hpp:9:
In file included from C:\\lib\\boost_1_69_0\boost/date_time/time_clock.hpp:16:
C:\\lib\\boost_1_69_0\boost/date_time/c_time.hpp:110:23: warning: 'gmtime' is deprecated: This function or variable may be unsafe. Consider using gmtime_s instead. To disable deprecation, use
_CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
result = std::gmtime(t);
^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\time.h:495:24: note: 'gmtime' has been explicitly marked deprecated here
_Check_return_ _CRT_INSECURE_DEPRECATE(gmtime_s)
^
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:255:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
^
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vcruntime.h:245:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
In file included from main.cpp:1:
In file included from C:\\lib\\boost_1_69_0\boost/thread.hpp:24:
In file included from C:\\lib\\boost_1_69_0\boost/thread/future.hpp:34:
In file included from C:\\lib\\boost_1_69_0\boost/thread/exceptional_ptr.hpp:10:
In file included from C:\\lib\\boost_1_69_0\boost/exception_ptr.hpp:9:
In file included from C:\\lib\\boost_1_69_0\boost/exception/detail/exception_ptr.hpp:14:
C:\\lib\\boost_1_69_0\boost/exception/info.hpp:85:67: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
^
3 warnings generated.
main-4f7529.o : warning LNK4217: locally defined symbol __std_terminate imported in function "int `public: __cdecl std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)'::`1'::dtor$5" (?dtor$5@?0???1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAA@XZ@4HA)
main-4f7529.o : warning LNK4217: locally defined symbol _CxxThrowException imported in function "public: void __cdecl std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QEAAXH_N@Z)
main-4f7529.o : error LNK2019: unresolved external symbol "__declspec(dllimport) bool __cdecl boost::this_thread::interruptible_wait(void *,struct boost::detail::mono_platform_timepoint const &)" (__imp_?interruptible_wait@this_thread@boost@@YA_NPEAXAEBUmono_platform_timepoint@detail@2@@Z) referenced in function "void __cdecl boost::this_thread::sleep_for<__int64,class boost::ratio<1,1> >(class boost::chrono::duration<__int64,class boost::ratio<1,1> > const &)" (??$sleep_for@_JV?$ratio@$00$00@boost@@@this_thread@boost@@YAXAEBV?$duration@_JV?$ratio@$00$00@boost@@@chrono@1@@Z)
main-4f7529.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl boost::thread::join(void)" (__imp_?join@thread@boost@@QEAAXXZ) referenced in function main
main-4f7529.o : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl boost::thread::~thread(void)" (__imp_??1thread@boost@@QEAA@XZ) referenced in function main
main-4f7529.o : error LNK2019: unresolved external symbol "__declspec(dllimport) private: static class boost::intrusive_ptr<struct boost::detail::thread_data_base> __cdecl boost::thread::make_thread_info(void (__cdecl*)(void))" (__imp_?make_thread_info@thread@boost@@CA?AV?$intrusive_ptr@Uthread_data_base@detail@boost@@@2@P6AXXZ@Z) referenced in function "public: __cdecl boost::thread::thread<void (__cdecl&)(void)>(void (__cdecl&)(void))" (??$?0A6AXXZ@thread@boost@@QEAA@A6AXXZ@Z)
main-4f7529.o : error LNK2019: unresolved external symbol "__declspec(dllimport) private: void __cdecl boost::thread::start_thread(void)" (__imp_?start_thread@thread@boost@@AEAAXXZ) referenced in function "public: __cdecl boost::thread::thread<void (__cdecl&)(void)>(void (__cdecl&)(void))" (??$?0A6AXXZ@thread@boost@@QEAA@A6AXXZ@Z)
a.exe : fatal error LNK1120: 5 unresolved externals
clang++: error: linker command failed with exit code 1120 (use -v to see invocation)
c:\eclipse-workspace\boost_thread>

c:\eclipse-workspace\boost_thread>

Paavo Helde

unread,
Feb 17, 2019, 2:45:08 AM2/17/19
to
On 17.02.2019 6:20, Mark wrote:
>
> I installed clang v9.0 on a windows 7 asset. I installed boost and compiled it as follows:
>
> C:\Temp\boost_1_69_0>bootstrap.bat –toolset=clang
> C:\Temp\boost_1_69_0> b2 -j8 toolset=clang address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --layout=versioned --build-type=complete stage
[...]
>
> Banging my head against a linker issue shown below. One incredibly confusing aspect with the output below is the Visual Studio 2017 Professional references. I'm not interested in using visual studio at all yet it appears Visual Studio 2017 runtime headers are being referenced. This is my first rodeo with clang on a Windows asset and wasn't anticipating this much pain. I suspect I'm not in the right forum but hopeful someone can help. Thoughts?

It appears clang is indeed using Microsoft runtimes on Windows.

From https://clang.llvm.org/docs/MSVCCompatibility.html :
"If you don’t require MSVC ABI compatibility or don’t want to use
Microsoft’s C and C++ runtimes, the mingw32 toolchain might be a better
fit for your project."

> C:\\lib\\boost_1_69_0\boost/date_time/c_time.hpp:101:23: warning: 'localtime' is deprecated: This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use
> _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
> result = std::localtime(t);

Welcome to the MS world! You will need to define several macros and
pragmas to get standards-conforming code compiling cleanly.

> main-4f7529.o : error LNK2019: unresolved external symbol "__declspec(dllimport) bool __cdecl boost::this_thread::interruptible_wait(void *,struct boost::detail::mono_platform_timepoint const &)" (__imp_?interruptible_wait@this_thread@boost@@YA_NPEAXAEBUmono_platform_timepoint@detail@2@@Z) referenced in function "void __cdecl boost::this_thread::sleep_for<__int64,class boost::ratio<1,1> >(class boost::chrono::duration<__int64,class boost::ratio<1,1> > const &)" (??$sleep_for@_JV?$ratio@$00$00@boost@@@this_thread@boost@@YAXAEBV?$duration@_JV?$ratio@$00$00@boost@@@chrono@1@@Z)

You have instructed the boost libraries to be built as static
(link=static), but here some main program is linked against a
non-existing dynamic library (__declspec(dllimport)). This is likely a
glitch in the boost build system, the support for static libraries has
been flaky all the time. Suggesting to seek help in a Boost forum.

PS. The standard threading support in current C++ compilers, including
VS2017, is pretty good, so you might consider porting your threading
code to standard C++ instead. The main Boost features missing in std are
thread cancellation and implicit detach, both of which are a bit
error-prone and should be avoided anyway.

0 new messages