FrozenHeart
FrozenHeart

Reputation: 20726

"Could not find boost libraries" error when using CMake

I have the following CMakeLists.txt file:

cmake_minimum_required(VERSION 2.6)

project (some_project)

set(BOOST_ROOT "E:/libs/boost_1_54_0")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

set (SOURCES 
    main.cpp) 

add_executable (${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

enable_testing ()
add_test (${PROJECT_NAME} ${PROJECT_NAME})

When I'm trying to use CMake with this file I've got the following error:

cmake.exe .
-- Building for: Visual Studio 12
-- The C compiler identification is MSVC 18.0.21005.1
-- The CXX compiler identification is MSVC 18.0.21005.1
-- Check for working C compiler using: Visual Studio 12
-- Check for working C compiler using: Visual Studio 12 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12
-- Check for working CXX compiler using: Visual Studio 12 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at e:/software/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1111 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.54.0

  Boost include path: E:/libs/boost_1_54_0

  Could not find the following static Boost libraries:

          boost_unit_test_framework

  No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.
Call Stack (most recent call first):
  CMakeLists.txt:8 (find_package)


-- Configuring incomplete, errors occurred!

In the "e:\libs\boost_1_54_0\stage\lib\" directory I have the following *.lib files:

libboost_unit_test_framework-vc110-mt-1_54.lib
libboost_unit_test_framework-vc110-mt-gd-1_54.lib
libboost_unit_test_framework-vc110-mt-s-1_54.lib
libboost_unit_test_framework-vc110-mt-sgd-1_54.lib

What am I doing wrong?

Upvotes: 2

Views: 5445

Answers (2)

ComicSansMS
ComicSansMS

Reputation: 54589

The version numbers of Visual Studio are a mess. VS10 is Visual Studio 10, but VS11 is Visual Studio 2012, while VS12 is Visual Studio 2013.

You simply selected the wrong generator in CMake. If you want to build for 2012, the correct generator is Visual Studio 11. Just delete your CMakeCache.txt and run CMake again with the correct generator:

cmake -G "Visual Studio 11" .

Oh, and while we're at it: Consider doing an out-of-source build instead, it's just way more fun that way.

Other than that your setup is completely fine.

Upvotes: 1

ToniBig
ToniBig

Reputation: 836

Instead of

set(BOOST_ROOT "E:/libs/boost_1_54_0")
...
find_package(Boost COMPONENTS unit_test_framework REQUIRED)

, I suggest you try only

find_package(Boost COMPONENTS unit_test_framework REQUIRED HINT "E:/libs/boost_1_54_0").

Upvotes: 0

Related Questions