conan-center-index: [package] boost/1.72.0: broken on windows due apparently to implicit link to libboost_unit_test_framework

Package and Environment Details (include every applicable attribute)

  • Package Name/Version: boost/1.72.0, also reproduced with boost/1.71.0
  • Operating System+version: Windows 10
  • Compiler+version: visual studio 2019
  • Conan version: conan 1.22.2
  • Python version: Python 3.7.4

Conan profile (output of conan profile show default or conan profile show <profile> if custom profile is in use)

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=15
build_type=Release
[options]
[build_requires]
[env]

Steps to reproduce (Include if Applicable)

CMakeLists.txt (just a single executable built from empty source, linking against boost/1.72.0):

include(cmake/conan.cmake)
find_package (Python3 COMPONENTS Interpreter)
get_filename_component(PATH_PYTHON3 ${Python3_EXECUTABLE} DIRECTORY)
find_program(CONAN_CMD conan HINTS ${PATH_PYTHON3} PATH_SUFFIXES Scripts)
conan_cmake_run(REQUIRES
    boost/1.72.0
    BASIC_SETUP
    CMAKE_TARGETS
    CONAN_COMMAND ${CONAN_CMD}

    OPTIONS
    BUILD missing
    GENERATORS cmake_find_package)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR} ${CMAKE_PREFIX_PATH})
find_package(Boost REQUIRED)

add_executable(boost_test)
target_sources(boost_test PRIVATE empty_file.cpp)
target_link_libraries(boost_test PRIVATE Boost::Boost

empty_file.cpp

cmake . cmake --build .

Logs (Include/Attach if Applicable)

(omitting compile)

FAILED: bin/boost-test.exe 
  cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=test\CMakeFiles\test.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~4\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\link.exe /nologo test\CMakeFiles\boost_test.dir\empty_file.cpp.obj  /out:bin\boost_test.exe /implib:lib\boost_test.lib /pdb:bin\boost_test.pdb /version:0.0  /machine:x64 /debug /INCREMENTAL /subsystem:console  C:\.conan\0e858b\1\lib\libboost_wave.lib  C:\.conan\0e858b\1\lib\libboost_container.lib  C:\.conan\0e858b\1\lib\libboost_contract.lib  C:\.conan\0e858b\1\lib\libboost_exception.lib  C:\.conan\0e858b\1\lib\libboost_graph.lib  C:\.conan\0e858b\1\lib\libboost_iostreams.lib  C:\.conan\0e858b\1\lib\libboost_locale.lib  C:\.conan\0e858b\1\lib\libboost_log.lib  C:\.conan\0e858b\1\lib\libboost_program_options.lib  C:\.conan\0e858b\1\lib\libboost_random.lib  C:\.conan\0e858b\1\lib\libboost_regex.lib  C:\.conan\0e858b\1\lib\libboost_serialization.lib  C:\.conan\0e858b\1\lib\libboost_wserialization.lib  C:\.conan\0e858b\1\lib\libboost_coroutine.lib  C:\.conan\0e858b\1\lib\libboost_fiber.lib  C:\.conan\0e858b\1\lib\libboost_context.lib  C:\.conan\0e858b\1\lib\libboost_timer.lib  C:\.conan\0e858b\1\lib\libboost_thread.lib  C:\.conan\0e858b\1\lib\libboost_chrono.lib  C:\.conan\0e858b\1\lib\libboost_date_time.lib  C:\.conan\0e858b\1\lib\libboost_atomic.lib  C:\.conan\0e858b\1\lib\libboost_filesystem.lib  C:\.conan\0e858b\1\lib\libboost_system.lib  C:\.conan\0e858b\1\lib\libboost_type_erasure.lib  C:\.conan\0e858b\1\lib\libboost_log_setup.lib  C:\.conan\0e858b\1\lib\libboost_math_c99.lib  C:\.conan\0e858b\1\lib\libboost_math_c99f.lib  C:\.conan\0e858b\1\lib\libboost_math_c99l.lib  C:\.conan\0e858b\1\lib\libboost_math_tr1.lib  C:\.conan\0e858b\1\lib\libboost_math_tr1f.lib  C:\.conan\0e858b\1\lib\libboost_math_tr1l.lib  C:\.conan\0e858b\1\lib\libboost_stacktrace_noop.lib  C:\.conan\0e858b\1\lib\libboost_stacktrace_windbg.lib  C:\.conan\0e858b\1\lib\libboost_stacktrace_windbg_cached.lib  C:\.conan\0e858b\1\lib\libboost_unit_test_framework.lib  bcrypt.lib  C:\Users\Tobi\.conan\data\zlib\1.2.11\_\_\package\75ed07303f056424be45ffb582032fe7ad980a95\lib\zlib.lib  C:\Users\Tobi\.conan\data\bzip2\1.0.8\_\_\package\8f5b6f2424f382951ec41d70bf48f85f9cf3c5b4\lib\bz2.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
  LINK Pass 1: command "C:\PROGRA~2\MICROS~4\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\link.exe /nologo test\CMakeFiles\boost_test.dir\empty_file.cpp.obj /out:bin\boost_test.exe /implib:lib\boost_test.lib /pdb:bin\boost_Test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\.conan\0e858b\1\lib\libboost_wave.lib C:\.conan\0e858b\1\lib\libboost_container.lib C:\.conan\0e858b\1\lib\libboost_contract.lib C:\.conan\0e858b\1\lib\libboost_exception.lib C:\.conan\0e858b\1\lib\libboost_graph.lib C:\.conan\0e858b\1\lib\libboost_iostreams.lib C:\.conan\0e858b\1\lib\libboost_locale.lib C:\.conan\0e858b\1\lib\libboost_log.lib C:\.conan\0e858b\1\lib\libboost_program_options.lib C:\.conan\0e858b\1\lib\libboost_random.lib C:\.conan\0e858b\1\lib\libboost_regex.lib C:\.conan\0e858b\1\lib\libboost_serialization.lib C:\.conan\0e858b\1\lib\libboost_wserialization.lib C:\.conan\0e858b\1\lib\libboost_coroutine.lib C:\.conan\0e858b\1\lib\libboost_fiber.lib C:\.conan\0e858b\1\lib\libboost_context.lib C:\.conan\0e858b\1\lib\libboost_timer.lib C:\.conan\0e858b\1\lib\libboost_thread.lib C:\.conan\0e858b\1\lib\libboost_chrono.lib C:\.conan\0e858b\1\lib\libboost_date_time.lib C:\.conan\0e858b\1\lib\libboost_atomic.lib C:\.conan\0e858b\1\lib\libboost_filesystem.lib C:\.conan\0e858b\1\lib\libboost_system.lib C:\.conan\0e858b\1\lib\libboost_type_erasure.lib C:\.conan\0e858b\1\lib\libboost_log_setup.lib C:\.conan\0e858b\1\lib\libboost_math_c99.lib C:\.conan\0e858b\1\lib\libboost_math_c99f.lib C:\.conan\0e858b\1\lib\libboost_math_c99l.lib C:\.conan\0e858b\1\lib\libboost_math_tr1.lib C:\.conan\0e858b\1\lib\libboost_math_tr1f.lib C:\.conan\0e858b\1\lib\libboost_math_tr1l.lib C:\.conan\0e858b\1\lib\libboost_stacktrace_noop.lib C:\.conan\0e858b\1\lib\libboost_stacktrace_windbg.lib C:\.conan\0e858b\1\lib\libboost_stacktrace_windbg_cached.lib C:\.conan\0e858b\1\lib\libboost_unit_test_framework.lib bcrypt.lib C:\Users\Tobi\.conan\data\zlib\1.2.11\_\_\package\75ed07303f056424be45ffb582032fe7ad980a95\lib\zlib.lib C:\Users\Tobi\.conan\data\bzip2\1.0.8\_\_\package\8f5b6f2424f382951ec41d70bf48f85f9cf3c5b4\lib\bz2.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:test\CMakeFiles\boost_test.dir/intermediate.manifest test\CMakeFiles\boost_test.dir/manifest.res" failed (exit code 1120) with the following output:
C:\Users\tobi\test\libboost_unit_test_framework.lib(unit_test_main.obj) : error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite@@YAPEAVtest_suite@unit_test@boost@@HQEAPEAD@Z) referenced in function main
C:\Users\Tobi\test\CMakefiles\boost_test/boost_test.exe : fatal error LNK1120: 1 unresolved externals

Note the path to the missing C:\Users\tobi\test\libboost_unit_test_framework.lib – that is inside my source tree. I’m fairly sure that what happens is that boost uses one of the magic #pragmas offered by Visual C++ to pull in the unit_test library, but the path is messed up (relative instead of absolute).

Note that I’m using the default “magic_autolink” is therefore false.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

You can workaround the problem in the case if you don’t want to use the boost::unit_test framework (UTF) at all but you want to use a gtest framework with other boost libraries. You can create an other package with a package receipt option “boost:without_test=True”. This will recompile the whole boost on your machine although.

So here is a sample conanfile.txt for the workaround:

[requires]
boost/1.71.0@conan/stable

[generators]
cmake

[options]
boost:without_test=True

If you are using the latest version of Conan make sure to like against the correct target (assuming you are using cmake) for GTest to not include the main. I see ninja but I’m not familiar with to suggest something.

If you want gtest and not boost test, you may be able to workaround by using the options, but I am not sure (off the top of my head) how.

Most unit test frameworks provide the ability to define your own main() which is another alternative.

https://docs.conan.io/en/latest/reference/generators/cmake_find_package.html?highlight=components#components

This new feature allows consumers to select which libs they can’t to link against

One recipe that allows you to pick and choose…

However I am not sure that fixes you’re issue =?

Perhaps we need a new lib for the unit test… This way you can do “without_unit_test” https://github.com/conan-io/conan-center-index/blob/5e8df010fb0b7c88e132cd22dac40cd3c4007b17/recipes/boost/all/conanfile.py#L19