Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Header-only mode with multiple translation units requires BOOST_TEST_NO_LIB #263

Closed
valiko-ua opened this issue Apr 3, 2020 · 5 comments
Assignees
Labels
Milestone

Comments

@valiko-ua
Copy link

According to documentation, BOOST_TEST_NO_LIB macro is not required when building multiple translation units in header-only mode, but I get the following error on Windows:

1>------ Rebuild All started: Project: MyTest, Configuration: Debug x64 ------
1>test_main.cpp
1>test2.cpp
1>Generating Code...
1>LINK : fatal error LNK1104: cannot open file 'libboost_unit_test_framework-vc142-mt-gd-x64-1_72.lib'
1>Done building project "MyTest.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Defining BOOST_TEST_NO_LIB macro in all additional translation units (the ones that include boost/test/unit_test.hpp) fixes the problem. If boost/test/detail/config.hpp cannot be enhanced somehow to fix this problem, then documentation should mention that BOOST_TEST_NO_LIB macro is required for the described case in all additional translation units (or just in all translation units).

There is no problem when project contains only one translation unit (which includes boost/test/included/unit_test.hpp).

Minimum example

Linker settings should not contain path to boost binary libraries to reproduce this problem.
File test_main.cpp:

#define BOOST_TEST_MODULE My Test
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test1)
{
    int i = 1;
    BOOST_TEST(i == 1);
    BOOST_TEST(i == 2);
}

File test2.cpp:

//#define BOOST_TEST_NO_LIB // uncomment this line to fix link error
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test2)
{
    int i = 2;
    BOOST_TEST(i == 1);
    BOOST_TEST(i == 2);
}
@raffienficiaud
Copy link
Member

raffienficiaud commented Apr 3, 2020

This is odd because there is a unit test covering this case on Windows: https://github.com/boostorg/test/blob/develop/test/Jamfile.v2#L137
Do you know what is defining BOOST_TEST_NO_LIB ?

Ok, now I think I know why the tests are not catching the issue. Thanks for the report

@raffienficiaud
Copy link
Member

Fix available on branch topic/GH-263-header-variant-test-no-lib. If you have some time, it would be nice if you can give a try.

@valiko-ua
Copy link
Author

The fix works, thanks!

@raffienficiaud
Copy link
Member

Thanks for the quick feedback!

@raffienficiaud raffienficiaud added next In "next" branch develop and removed fix-proposed next In "next" branch develop labels Apr 6, 2020
@raffienficiaud
Copy link
Member

Fix in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants