I installed the boost library. After i also build libraries via ./bootstrap and ./b2.
But for some reason, when building in QT Creator gives me this errors:
LNK2019: unresolved external symbol "bool __cdecl boost::this_thread::interruptible_wait(void *,struct boost::detail::mono_platform_timepoint const &)" (?interruptible_wait@this_thread@boost@@YA_NPEAXAEBUmono_platform_timepoint@detail@2@@Z) referenced in function "void __cdecl boost::this_thread::sleep_for<__int64,struct std::ratio<1,1> >(class boost::chrono::duration<__int64,struct std::ratio<1,1> > const &)" (??$sleep_for@_JU?$ratio@$00$00@std@@@this_thread@boost@@YAXAEBV?$duration@_JU?$ratio@$00$00@std@@@chrono@1@@Z)
testin.exe:-1: error: LNK1120: 1 unresolved externals
:-1: error: ninja: build stopped: subcommand failed.
Here’s my simple code example:
#include <iostream>
#include "boost/chrono.hpp"
#include "boost/thread.hpp"
int main()
{
boost::this_thread::sleep_for(boost::chrono::seconds(1));
return 0;
}
Here’s my CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project(testin LANGUAGES CXX)
add_executable(testin main.cpp)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ROOT "C:/libraries/boost_1_85_0")
set(BOOST_INCLUDEDIR "C:/libraries/boost_1_85_0")
set(BOOST_LIBRARYDIR "C:/libraries/boost_1_85_0/lib64-msvc-14.3")
add_definitions(-DBOOST_ALL_NO_LIB)
find_package(Boost 1.85.0 REQUIRED)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${BOOST_LIBRARYDIR})
target_link_libraries(testin Qt${QT_VERSION_MAJOR}::Core)
include(GNUInstallDirs)
install(TARGETS testin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
I suspect that the problem is in my CMakLists.txt. Because a similar code works without problems in Visual Studio 2022. But my problem arises when using CMakeLists.txt in Qt Creator.