0

I am newbie in CMake and I can't understand why CMake can't find one of the Boost libraries. (Using Qt Creator and Windows 10)

This is my CMake file:

cmake_minimum_required(VERSION 2.8)

project(Libtorrent)

add_executable(${PROJECT_NAME} "main.cpp")

link_directories(
   e:/lib/boost_1_69_0/lib64-msvc-14.1/
    )
target_link_libraries (${PROJECT_NAME} libboost_atomic-vc141-mt-gd-x64-1_69)

include_directories(
    e:/lib/boost_1_69_0
    e:/lib/libtorrent/libtorrent_msvc141_64/include
)

And i recieve:

error: LNK1104: cannot open file 'libboost_atomic-vc141-mt-gd-x64-1_69.lib'

Stefan
  • 17,448
  • 11
  • 60
  • 79
ExiD
  • 87
  • 2
  • 12
  • 2
    Use `find_package(Boost COMPONENTS atomic)`, make sure it's found properly, and use then `target_link_directories(${PROJECT_NAME} ${Boost_ATOMIC_LIBRARY})` – Matthieu Brucher Dec 14 '18 at 13:29
  • @MatthieuBrucher `Found the following Boost libraries: atomic`. And you mean `target_link_libraries`? This is also has no effect – ExiD Dec 14 '18 at 13:35
  • i saw that lib files linked in CMake has only "boost..." name. But i need "libboost...". What's wrong? – ExiD Dec 14 '18 at 13:42
  • Possible duplicate of [Cmake cannot find library using "link\_directories"](https://stackoverflow.com/questions/31438916/cmake-cannot-find-library-using-link-directories). Your case is described in the [second answer](https://stackoverflow.com/a/40554704/3440745) - `link_directories` should precede `add_executable` for take an effect. – Tsyvarev Dec 14 '18 at 14:26
  • Read [the CMake documentation for finding boost libraries](https://cmake.org/cmake/help/v3.8/module/FindBoost.html) – Mike Kinghan Dec 14 '18 at 14:27
  • You should set a combination of the following variables before the `find_package(boost ...)` call. Since you are trying to link against the static boost libraries I would add: `set(Boost_USE_STATIC_LIBS ON)` `set(Boost_USE_MULTITHREADED ON)` `set(Boost_USE_STATIC_RUNTIME ON)` . The latter variable may need to be set to `OFF` according to your dependencies. – vre Dec 14 '18 at 19:03

0 Answers0