仅标头版本中的提升单元测试链接器错误

问题描述 投票:0回答:0

通过从 boost.org 解压缩文件并运行 bootstrap.bat 和 b2.exe 来安装 Boost。完成后,stage\lib 目录中填充了一百多个 .LIB。

为了避免链接器错误,我尝试按照在其仅标头版本中使用 boost test 的说明进行操作(我知道已弃用)。这是我的完整文件,从 Boost 网站粘贴的相关部分:

#include <iostream>

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

#define BOOST_TEST_MODULE header-only multiunit test
#include <boost/test/included/unit_test.hpp>


BOOST_AUTO_TEST_CASE(test1)
{
    int i = 1;
    BOOST_CHECK(i * i == 1);
}


I expected it would in fact be header-only but the build output (VS if it matters) is
> 1>LINK : fatal error LNK1104: cannot open file 'C:\Users\beryl\Downloads\boost_1_81_0\stage\lib.obj'

The library directory seems correctly set, as proven by the disappearance of other linker errors. If I missed a problem with
> $(CoreLibraryDependencies);%(AdditionalDependencies); C:\Users\beryl\Downloads\boost_1_81_0\stage\lib\
then that might explain things, but it looks right. (EDIT: if the problem with that was infuriatingly obvious to you, skip to the bottom). 

The problem is there is no file "lib.obj" in (mumble)\stage\lib. 

I have tried comparing to another installation. A package manager's installation of boost-test has no lib.obj.

I have tried dir /S on lib.obj. It's not anywhere. 

I have tried Googling various combinations of Boost and lib.obj. 

I have tried to figure out why Boost would be trying to link to a .obj instead of a .lib. That does feel like the horse on the dining room table. 

I have done a findstr to see if there was a pragma comment linking to lib.obj. None. 

I have tried the library path in the VS project properties with and without a final backslash. It's the same either way. 

So, the question is:
What is the most straightforward path from where I am now to being able to experiment with Boost unit tests, in any version or configuration?

I'll go ahead and submit this even though I just fixed it on my own, in case someone is Googling the problem in the future. It was, of course, a stupid mistake. Boost's library directory belonged in the additional library directories property and not in the additional dependencies property. With that changed, it built without error. 



Oops, I packed everything into the other window, sorry. 

In a nutshell, I expected to build it without error and got a linker error, which turned out to have nothing to do with Boost but was the result of putting the Boost library path in the wrong place in the Visual Studio project file. 
boost linker-errors boost-test
© www.soinside.com 2019 - 2024. All rights reserved.