0

im learning boost,i want to link boost_thread.lib,so here are my CMakeLists:

cmake_minimum_required(VERSION 3.19)
project(boost)

set(CMAKE_CXX_STANDARD 20)
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
aux_source_directory(. DIR_SRCS)
add_executable(main ${DIR_SRCS})
target_link_libraries(main boost_thread pthread)

here are myproject structure enter image description here

error:

C:/PROGRA~1/MINGW-~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_thread
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\main.dir\build.make:105: ../bin/main.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:94: CMakeFiles/main.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:101: CMakeFiles/main.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:136: main] Error 2

where are wrong?thank for help

Rain
  • 1
  • 1
  • sorry,i forget. – Rain Apr 25 '22 at 15:20
  • 1
    How did you install mingw binaries for boost? Remember you need mingw compiled binaries and not ones for mscv. My advice is to remove your old version of mingw and install msys2 for an updated mingw with gcc-11.2 and have it install boost for you using its builtin package manager pacman – drescherjm Apr 25 '22 at 15:34
  • Looking at the picture, you have boost binaries built for msvc. Those are not compatible with mingw. – drescherjm Apr 25 '22 at 15:36
  • 1
    the linker will be looking for a file named `libboost_thread.a`, as that file doesn't exist it fails. As above, you can't link the MSVC version of boost with GCC – Alan Birtles Apr 25 '22 at 15:43
  • Related to installing mingw from msys2: [https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2) – drescherjm Apr 25 '22 at 15:54

0 Answers0