Defining BOOST_TEST_DYN_LINK Crashes the Application in Visual Studio

In the documentation for testing the accelerator, it states that you need to define BOOST_TEST_DYN_LINK in order to link the boost unit test library.

I am using this basic example:

#define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE test_module1 // This header is for the dynamic library, not the header only one #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE(test1) { BOOST_CHECK(true); } 

I added an add / library to my paths and compiling the code is fine, but when I compile the boost module tests with Visual Studio and try to run them, I get the following error:

The application could not start correctly (0xc000003b).

It seems to me that I just need to indicate how vague and not useful this error message is at all ...

For some reason, if I delete the #define BOOST_TEST_DYN_LINK line, the code will compile and run successfully, but this is directly related to what the acceleration documentation says.

Why is this happening?


Additional Information:

This is what I use:

boost v1_63_0

enter image description here

+5
source share
3 answers

I have no problem running your code. Therefore, I doubt that in your case there is a problem with the construction.

My boost is built this way (after going to the Boost source directory):

 bootstrap.bat .\b2.exe toolset=msvc -j 2 --with-test release link=shared stage 

Then you need to copy the DLLs under the \ lib scene somewhere along your path and add the appropriate Boost directories to your environment. For my command line environment I have (if you did something like set BOOST_ROOT=C:\src\boost_1_65_1 ):

 set INCLUDE=%BOOST_ROOT%;%INCLUDE% set LIB=%BOOST_ROOT%\stage\lib;%LIB% 

Then I can successfully compile the test code without any problems:

 cl /EHsc /MD test.cpp .\test.exe 
+3
source

Regarding why, it is, of course, because you include / insert both static and dynamic (dll) options in your code. This can happen in MSVC because Boost uses the compiler auto linker. I always use BOOST_ALL_NO_LIB to turn off automatic linking and have full control over linked libraries.

In particular, the auto-link libraries, when used, are not visible in the link options, making it difficult to find problems.

+2
source

Then just do not define BOOST_TEST_DYN_LINK when using Visual Studio.

The main file of our device contains:

 #ifndef _MSC_VER #define BOOST_TEST_DYN_LINK #endif #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE Main #include <boost/test/unit_test.hpp> 

It works great on Linux using GCC and Windows , using both Visual Studio and MinGw .

0
source

Source: https://habr.com/ru/post/1271224/


All Articles