Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exception HRESULT: 0x800700C1 when executing c# application referencing native c++ lib with boost

I am running a C# application that references a C++\CLI wrapper project which in turn references a native c++ project dependent on Boost 1.47 library (links to files of the form ...vc100-mt-gd-1_47.lib)

All libraries are statically linked and everything compiles great. Executing the C# app results in an exception: "...is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)." claiming some dependency is missing somewhere.

C# application is configured to x86 platform while all other projects are Win32, including boost's binaries.

EDIT: before adding the use of Boost library, it DID work

How can I track down the problem?

like image 917
Leo Avatar asked Nov 11 '11 10:11

Leo


1 Answers

It is known issue. The reason is Thread Local Storage (TLS) used in the Boost::Thread. To fix it you should either disable libboost_thread-vcXXX-mt-1_XX.lib and force linker to link your C++/CLI assembly with boost_thread-vcXXX-mt-1_XX.lib (stub of the boost_thread-vcXXX-mt-1_XX.dll).

Or you can create your own DLL and link it with libboost_thread-vcXXX-mt-1_XX.lib. Then you can link your C++ DLL with C++/CLI assembly.

See

  • Using boost threads when compiling with /clr
  • Boost Threads with CLR
  • Using boost in CLR
like image 172
Dmytro Ovdiienko Avatar answered Sep 28 '22 10:09

Dmytro Ovdiienko