[CMake] Unable to locate boost_unit_test_framework-vc90-mt-gd-1_45.lib

Michael Hertling mhertling at online.de
Mon Aug 15 21:54:28 EDT 2011


On 08/11/2011 04:30 PM, Stephen Torri wrote:
> On Wed, Aug 10, 2011 at 9:51 PM, Michael Hertling <mhertling at online.de>wrote:
> 
>>  On 08/10/2011 04:27 PM, Stephen Torri wrote:
>>> I am having a problem setting up CMake to find the Boost unit test
>> framework
>>> library when building a test program. In the top level CMakeLists.txt
>> file I
>>> have:
>>>
>>> ENABLE_TESTING()
>>>
>>> add_subdirectory ( path/to/test )
>>>
>>> In the test directory CMakeLists.txt file I have:
>>>
>>> LINK_DIRECTORIES ( ${Boost_LIBRARY_DIRS} )
>>> ADD_EXECUTABLE ( test test.cpp )
>>> ADD_TEST ( test ${CMAKE_CURRENT_BINARY_DIR}/test )
>>>
>>> I added the LINK_DIRECTORIES because I though that the linker was not
>>> getting the path to the Boost library. That is wrong since the full path
>> to
>>> the library is in the properties for this project. So I figured since it
>> had
>>> the full name it should be able to find it. Not quite.
>>>
>>> The error message I get says:
>>>
>>> LNK1104: cannot open file 'boost_unit_test_framework-vc90-mt-gd-1_45.lib'
>>>
>>> I have boost installed in C:\boost. The FIND_BOOST macro able to find the
>>> installation headers and libraries I require. The only thing that is
>>> different is that the directory has the Boost unit test framework named
>> as:
>>>
>>> C:\boost\lib\libboost_unit_test_framework-vc90-mt-gd-1_45.lib
>>>
>>> That name, libboost_unit_test...., is different from the expected name of
>>> boost_unit_test...
>>>
>>> I am at a loss as to why this is the case.
>>>
>>> CMake version: 2.8.4
>>> Boost version: 1.45
>>>
>>> Stephen
>>
>> Could you provide a minimal but complete example that demonstrates
>> the issue, perhaps along with the output from the build phase?
>>
>> Regards,
>>
>> Michael
>>
> Attached is a minimal example that shows the problem. Below is the output
> from the build log:
> 
> --------------------
> build.log
> --------------------
> 
> 
> Creating temporary file "c:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\test.dir\Debug\RSP00001A37404960.rsp"
> with contents
> 
> [
> 
> /Od /I "C:\boost" /I "C:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio 2008\Projects\problem_boost_test" /D "WIN32" /D
> "_WINDOWS" /D "_DEBUG" /D "CMAKE_INTDIR=\"Debug\"" /D "_MBCS" /FD /EHsc
> /RTC1 /MDd /Fo"test.dir\Debug\\" /Fd"C:\Documents and
> Settings\Stephen.Torri\My Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\Debug/test.pdb" /W3
> /c /Zi /TP   /Zm1000
> 
> 
> 
> "..\..\..\mycode\Testing\test.cpp"
> 
> ]
> 
> Creating command line "cl.exe @"c:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\test.dir\Debug\RSP00001A37404960.rsp"
> /nologo /errorReport:prompt"
> 
> Creating temporary file "c:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\test.dir\Debug\RSP00001C37404960.rsp"
> with contents
> 
> [
> 
> /OUT:"C:\Documents and Settings\Stephen.Torri\My Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\Debug\test.exe"
> /VERSION:0.0 /INCREMENTAL /MANIFEST
> /MANIFESTFILE:"test.dir\Debug\test.exe.intermediate.manifest"
> /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Documents
> and Settings\Stephen.Torri\My Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\Debug/test.pdb"
> /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Documents and
> Settings\Stephen.Torri\My Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\Debug\test.lib"
>  /STACK:10000000
> /machine:X86 /debug kernel32.lib user32.lib gdi32.lib winspool.lib
> shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
> 
> 
> 
> ".\test.dir\Debug\test.obj"
> 
> 
> 
> ".\test.dir\Debug\test.exe.embed.manifest.res"
> 
> ]
> 
> Creating command line "link.exe @"c:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\test.dir\Debug\RSP00001C37404960.rsp"
> /NOLOGO /ERRORREPORT:PROMPT"
> 
> 
> 
> --------------------
> 
> Build output
> 
> --------------------
> 
> 
> 
> 1>------ Skipped Build: Project: RUN_TESTS, Configuration: Debug Win32
> ------
> 
> 1>Project not selected to build for this solution configuration
> 
> 2>------ Build started: Project: mycode, Configuration: Debug Win32 ------
> 
> 3>------ Build started: Project: test, Configuration: Debug Win32 ------
> 
> 2>Compiling...
> 
> 3>Compiling...
> 
> 2>mycode.cpp
> 
> 3>test.cpp
> 
> 2>Creating library...
> 
> 2>Build log was saved at "file://c:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\mycode.dir\Debug\BuildLog.htm<file:///c:/Documents%20and%20Settings/Stephen.Torri/My%20Documents/Visual%20Studio%202008/Projects/problem_boost_test/vs2008/mycode/mycode.dir/Debug/BuildLog.htm>
> "
> 
> 2>mycode - 0 error(s), 0 warning(s)
> 
> 3>Linking...
> 
> 3>LINK : fatal error LNK1104: cannot open file
> 'boost_unit_test_framework-vc90-mt-gd-1_45.lib'
> 
> 3>Build log was saved at "file://c:\Documents and Settings\Stephen.Torri\My
> Documents\Visual Studio
> 2008\Projects\problem_boost_test\vs2008\mycode\Testing\test.dir\Debug\BuildLog.htm<file:///c:/Documents%20and%20Settings/Stephen.Torri/My%20Documents/Visual%20Studio%202008/Projects/problem_boost_test/vs2008/mycode/Testing/test.dir/Debug/BuildLog.htm>
> "
> 
> 3>test - 1 error(s), 0 warning(s)
> 
> 4>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32
> ------
> 
> 4>Project not selected to build for this solution configuration
> 
> ========== Build: 1 succeeded, 1 failed, 1 up-to-date, 2 skipped ==========

First of all, I've never used the Boost auto-linking feature; instead,
I prefer the conventional way of immediately specifying libraries to
link against and have CMake find out mediate dependencies by itself.
So, I was able to successfully build your exemplary project on *nix
after the following modifications:

- Rename target "test" to "mytest". With Makefile generators, CMake
  itself defines a target "test" which collides with user-defined
  targets of the same name, so you may not name a target "test".
- Add TARGET_LINK_LIBRARIES(mytest mycode ${Boost_LIBRARIES}) to
  mycode/Testing/CMakeLists.txt. Your testing executable obviously
  needs to be linked against your mycode target and the Boost unit
  test library. By specifying ${Boost_LIBRARIES}, it's assured that
  you'll link against the libraries requested via FIND_PACKAGE(Boost)
  *and* their prerequisites, whereas linking against ${Boost_UNIT_TEST_
  FRAMEWORK_LIBRARY} only takes this specific library into account and
  leaves you with the possibility of unresolved references in case this
  library is itself linked against other Boost or third-party libraries.

Two additional remarks:

- When invoking FIND_PACKAGE(Boost) in the top-level CMakeLists.txt,
  note that the results propagate to the subdirectories, so ${Boost_
  LIBRARIES} might not contain the correct set of libraries for each
  subdirectory. Consider to call FIND_PACKAGE(Boost) with the desired
  components in the subdirectories' CMakeLists.txt files individually.
- In ADD_TEST(), it is not necessary to specify your test executable
  as ${CMAKE_CURRENT_BINARY_DIR}/mytest; CMake is able to figure out
  the executable target's path by itself, so ADD_TEST(mytest mytest)
  or better ADD_TEST(NAME mytest COMMAND mytest) is sufficient.

'hope that helps.

Regards,

Michael


More information about the CMake mailing list