boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
422 stars 70 forks source link

Fails to link when using clang compiler under Visual Studio #100

Closed MomoDeve closed 1 day ago

MomoDeve commented 3 years ago
D:\repos\MxEngine\out\build\x64-Clang-Debug\lld-link : error : undefined symbol: DebugCreate
  >>> referenced by D:\boost\boost\stacktrace\detail\frame_msvc.ipp:126
  >>>               MxEngine.lib(Platform.cpp.obj):(private: static void __cdecl boost::stacktrace::detail::debugging_symbols::try_init_com(class boost::stacktrace::detail::com_holder<struct IDebugSymbols> &, class boost::stacktrace::detail::com_global_initer const &))

Fixed by manually including winapi libraries:

#if defined(WIN32)
    #pragma comment(lib, "ole32.lib")
    #pragma comment(lib, "Dbgeng.lib")
#endif
#include <boost/stacktrace.hpp>
apolukhin commented 3 years ago

AFAIK MinGW* and cygwin compilers do not have auto linking support, so #if defined(WIN32) won't work right all the time.

Is there some macro to uniquely identify clang usage on visual studio?

MomoDeve commented 3 years ago

I havent found macro exactly for that, me myself checking it by writing #if defined(__clang__) && defined(_WIN32) Instead of _WIN32 there could also be _MSC_VER, clang sets it for compatibilty with msvc compiler if it was launched using Visual Studio toolchain