Reputation: 103
In a single Visual Studio 2015 solution, I have a WPF application, a C++/CLI DLL that 'wraps' a native C++ project (that compiles to a static LIB). All was working great until:
I added Boost Log to the native C++ project. Everything happy compiles but I get a BadFormatException with a message '<> is not a valid Win32 application' when attempting to run the WPF application.
I found in another answer here that I needed to change to use the DLL versions of Boost and added 'BOOST_ALL_DYN_LINK'. I have also confirmed that both the C++/CLI and native C++ projects are set to compile to Win32 and that WPF project compiles to x86.
If I leave the native C++ project as a LIB, everything compiles but I still get the same BadFormatException. I have copied the required Boost DLLs to the WPF application Debug directory (I used BOOST_LIB_DIAGNOSTIC to confirm which libraries I needed).
If I change the native C++ project to a DLL, it compiles but the C++/CLI project no longer links because it can't find the LIB file (shouldn't it now be looking for a DLL?).
Upvotes: 1
Views: 1824
Reputation: 13679
As far as I recall:
Even to link DLL you need LIB file, this LIB file is produced along with DLL, and contains references to the DLL.
Static linking with some boost libraries won't work in C++/CLI because they will rely on static TLS (thread local storage). Boost.Thread known to have this dependency, and Boost.Log probably uses Boost.Thread. If you have single-threaded code, you may try BOOST_LOG_NO_THREADS.
Upvotes: 1