0

I'm on Window (OS) and trying to do the Boost::Asio tutorial. I successfully added Boost but once I try to add a component (system, thread, regex, ...) it fails ... All of this is working on my Ubuntu. But on my Window (OS) it's not working ...

I installed boost to my pc then added it to my project thanks to CMake.

find_package(Boost 1.82.0 REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARY_DIRS})

Then I'm doing the Boost::Asio tutorials and I need to add the boost::thread. I alter my CMake to add the required boost components (system, thread and regex)

find_package(Boost 1.82.0 COMPONENTS system thread regex REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(${AJC_PROJECT_NAME} ${Boost_LIBRARY_DIRS} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY})

Then from now CMake is not working anymore :( Looking through stackoverflow and others ressources I added a few lines to my CMake

set(Boost_USE_STATIC_LIBS ON)
set(Boost_DEBUG ON)
find_package(Boost 1.82.0 COMPONENTS system thread regex REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(${AJC_PROJECT_NAME} ${Boost_LIBRARY_DIRS} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY})

I even tried

CMAKE -- set(Boost_NO_BOOST_CMAKE ON)
ENV -- BOOST_INCLUDEDIR = C:\boost_1_82_0\boost
ENV -- BOOST_LIBRARYDIR = C:\boost_1_82_0\stage\lib (and C:\boost_1_82_0\libs)
ENV -- BOOST_ROOT = C:\boost_1_82_0

but nothing works. I got the following errors (I bolded the stacktrace)

-- [ C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:2256 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-mgw13-mt-1_82;libboost_system-mgw13-mt;libboost_system-mgw13-mt;libboost_system-mt-1_82;libboost_system-mt;libboost_system-mt;libboost_system-mt;libboost_system;libboost_system-mgw13-mt-s-1_82;libboost_system-mgw13-mt-s;libboost_system-mgw13-mt-s;libboost_system-mt-s-1_82;libboost_system-mt-s;libboost_system-mt-s
-- [ C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:2311 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-mgw13-mt-d-1_82;libboost_system-mgw13-mt-d;libboost_system-mgw13-mt-d;libboost_system-mt-d-1_82;libboost_system-mt-d;libboost_system-mt-d;libboost_system-mt;libboost_system;libboost_system-mgw13-mt-s-d-1_82;libboost_system-mgw13-mt-s-d;libboost_system-mgw13-mt-s-d;libboost_system-mt-s-d-1_82;libboost_system-mt-s-d;libboost_system-mt-s-d
-- [ C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:807 ] Boost_LIBRARY_DIR_DEBUG = "C:/boost_1_82_0/stage/lib"
-- [ C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:809 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:/boost_1_82_0/stage/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
**!!!!!!!---------- same for thread, regex, chrono and atomic ----------!!!!!!!**
-- [ C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:807 ] Boost_LIBRARY_DIR_DEBUG = "C:/boost_1_82_0/stage/lib"
-- [ C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:809 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:/boost_1_82_0/stage/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
**CMake Error at C:/msys64/mingw64/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Boost (missing: system thread regex) (found suitable version
  "1.82.0", minimum required is "1.82.0")
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  C:/msys64/mingw64/share/cmake/Modules/FindBoost.cmake:2377 (find_package_handle_standard_args)
  CMakeLists.txt:31 (find_package)**

In the directory (C:\boost_1_82_0\stage\lib) I got all my libs in the following format

libboost_atomic-mgw13-mt-d-x64-1_82.a
libboost_atomic-mgw13-mt-sd-x64-1_82.a
libboost_atomic-mgw13-mt-s-x64-1_82.a
libboost_atomic-mgw13-mt-x64-1_82.a

All of this is working on my Ubuntu. But on my Window (OS) it's not working ... If anyone could help me It would be amazing.

PS - 1: When I alter the CMake to become

target_include_directories(${PROJECT_NAME} PUBLIC "C:/boost_1_82_0")
target_link_libraries(${PROJECT_NAME}
        "C:/boost_1_82_0/stage/lib/libboost_system-mgw13-mt-d-x64-1_82.a"
        "C:/boost_1_82_0/stage/lib/libboost_thread-mgw13-mt-d-x64-1_82.a"
        "C:/boost_1_82_0/stage/lib/libboost_regex-mgw13-mt-d-x64-1_82.a"
        "C:/boost_1_82_0/stage/lib/libboost_chrono-mgw13-mt-d-x64-1_82.a"
        "C:/boost_1_82_0/stage/lib/libboost_atomic-mgw13-mt-d-x64-1_82.a")

It works but I would like to make it work with find_package

  • Are you sure that libraries in /lib/ are compatible with your compiler and target arch? Because it looks like `find_package` is able to find header-only libs, but fails to find compiled libraries because they have `-x64` suffix. – Osyotr Jul 06 '23 at 23:02
  • You wrote *"I installed boost to my pc"* - however it looks like you've just unpacked boost into C:\ and build it. `find_package(Boost 1.82.0 REQUIRED)` implies that you have a "cmake package" somewhere. And "cmake package" is something defined by cmake package script bundled with cmake. In practice these scripts are rarely useful. It would be easier to just provide necessary settings without using find_package. – user7860670 Jul 07 '23 at 07:07
  • When I alter the CMake to become ``` target_include_directories(${PROJECT_NAME} PUBLIC "C:/boost_1_82_0") target_link_libraries(${PROJECT_NAME} "C:/boost_1_82_0/stage/lib/libboost_system-mgw13-mt-d-x64-1_82.a" "C:/boost_1_82_0/stage/lib/libboost_thread-mgw13-mt-d-x64-1_82.a" "C:/boost_1_82_0/stage/lib/libboost_regex-mgw13-mt-d-x64-1_82.a" "C:/boost_1_82_0/stage/lib/libboost_chrono-mgw13-mt-d-x64-1_82.a" "C:/boost_1_82_0/stage/lib/libboost_atomic-mgw13-mt-d-x64-1_82.a") ``` It works but I would like to make it work with find_package – Spectral Dev Jul 07 '23 at 07:31
  • If you installed the boost on your Windows correctly, the libs format should be *.lib or *.dll, not the *.a. – Tom Jul 07 '23 at 07:33
  • I installed them all in my stage/lib I have .a, .dll and .dll.a. – Spectral Dev Jul 07 '23 at 07:36
  • And @Tom not sure if it's change something but I work in VSCode or Clion with CMake. And it's working with .a (without the find_package) – Spectral Dev Jul 07 '23 at 07:37
  • @Spec `target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})` is enough, no need other components. – Tom Jul 07 '23 at 07:39
  • @Spec For the *.a can work on Windows, it has beyond my knowledge, I have no idea about that. – Tom Jul 07 '23 at 07:45
  • You are using the most recent version of Boost. Do you have an according new CMake version (3.27 release candidate)? This might otherwise cause problems, see https://stackoverflow.com/a/42124857/2799037 – usr1234567 Jul 07 '23 at 07:48
  • 1
    A few thing to check: 1) Can you print the value of `Boost_ROOT` variable? it should point to a directory that you have `/lib` and `/include` inside. 2) It seems that you are using the multi-threaded version of boost (`-mt-` in the name). Can you add `set(Boost_USE_MULTITHREADED ON)` before finding the boost package? 3) After calling `find_package` to find Boost, always use the `Boost_FOUND` variable to see if boost has been found properly or not. – TonySalimi Jul 07 '23 at 08:28
  • You did not specify what generator and what CMake version you were using. but I suppose you used the Windows CMake version and the default generator setting. To correctly find boost you must use the MSYS2/MinGW CMake version, i.e. you need to install the mingw-w64-i686-cmake and/or mingw-w64-x86_64-cmake packages. Delete the build directory and rerun your CMake command. – vre Jul 07 '23 at 14:16

0 Answers0