I've encountered this problem: linker cannot find Boost.Log library which clearly does exist in destination. I use MS Visual Studio 2022, so my compiler surely is msvc143
as stated in library.
I have environment variables set like this:
And my CMakeLists.txt is:
cmake_minimum_required(VERSION 3.28)
project(SMTPLogger)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(Boost 1.85 REQUIRED COMPONENTS log thread)
if(Boost_FOUND)
message(STATUS "Boost include directories: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARYDIR})
else()
message(FATAL_ERROR "Could not find Boost")
endif()
find_package(Threads REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/include)
add_executable(Logger src/Logger.cpp main.cpp)
target_include_directories(Logger PRIVATE ${CMAKE_SOURCE_DIR}/include ${Boost_INCLUDE_DIRS})
target_link_libraries(Logger Boost::log Boost::thread Threads::Threads)
When building, CMake outputs next message:
1> [CMake] CMake Warning at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindBoost.cmake:1398 (message):
1> [CMake] New Boost version may have incorrect or missing dependencies and imported
1> [CMake] targets
1> [CMake] Call Stack (most recent call first):
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindBoost.cmake:1523 (_Boost_COMPONENT_DEPENDENCIES)
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindBoost.cmake:2135 (_Boost_MISSING_DEPENDENCIES)
1> [CMake] CMakeLists.txt:7 (find_package)
In message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
there is no libboost_log-vc143-mt-gd-x64-1_85.lib:
1> [CMake] -- Boost include directories: C:/dev/utilities/boost_1_85_0
1> [CMake] -- Boost libraries: optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_log-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_log-vc143-mt-gd-x64-1_85.lib;
optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_thread-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_thread-vc143-mt-gd-x64-1_85.lib;
optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_log_setup-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_log_setup-vc143-mt-gd-x64-1_85.lib;
optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_filesystem-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_filesystem-vc143-mt-gd-x64-1_85.lib;
optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_regex-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_regex-vc143-mt-gd-x64-1_85.lib;
optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_chrono-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_chrono-vc143-mt-gd-x64-1_85.lib;
optimized;C:/dev/utilities/boost_1_85_0/stage/lib/boost_atomic-vc143-mt-x64-1_85.lib;
debug;C:/dev/utilities/boost_1_85_0/stage/lib/boost_atomic-vc143-mt-gd-x64-1_85.lib
As seen below, library is located in ${BOOST_LIBRARYDIR}
path.
As I researched the question, I realised that I cannot go to Configuration Properties and further, as there are none shown for CMake project. I`ve tried rebuilding, clearing CMake cache but nothing worked. I suppose the problem may lay in Boost version that I am currently using, 1.85.0, and CMake version 3.28.3
Thank you in advance.
When use find_package(Boost)
, it defines special target Boost::dynamic_linking
. Linking with that target automatically defines BOOST_ALL_DYN_LINK
macro, which is needed for use dynamic Boost libraries on Windows:
target_link_libraries(Logger Boost::log Boost::thread Boost::dynamic_linking Threads::Threads)