2

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?

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
  • 1
    Carefully read **[my other answer](http://stackoverflow.com/questions/19303430/cmake-cannot-find-boost-libraries/19318463#19318463)**, and especially all the comments below it, the ones about the fact that your libraries are for VS 11, but you are using VS 12. – Alexander Shukaev Dec 13 '13 at 20:28
  • @Haroogan What? msvc-11.0 is the compiler from Visual Studio 2012 – FrozenHeart Dec 13 '13 at 20:41
  • Oh, my bad. I thought it's showing the version of VS in libraries, right it's `vc110`. OK, then the first strange thing is `Boost include path: E:/libs/boost_1_54_0`. It should rather be `E:/libs/boost_1_54_0/include`. Furthermore, `link_directories(${Boost_LIBRARY_DIR})` is redundant, and you better use `Boost_INCLUDE_DIRS` - plural. – Alexander Shukaev Dec 13 '13 at 20:46
  • Run `set(Boost_DEBUG ON)` as well, let's see what you got. – Alexander Shukaev Dec 13 '13 at 20:48
  • @Haroogan boost doesn't even have "include" directory – FrozenHeart Dec 13 '13 at 20:48
  • Where are all the headers then? – Alexander Shukaev Dec 13 '13 at 20:49
  • BTW, In my build of boost-1.54.0 that I use with CMake I have a lib and an include folder and CMake finds this without much problem. – drescherjm Dec 13 '13 at 20:55
  • Oh, I think that it's a bug in CMake - note that CMake says "Building for: Visual Studio 12" while the next line says that we'll use MSVC 18.0.21005.1 which is from Visual Studio 2013 – FrozenHeart Dec 13 '13 at 21:01
  • 1
    No. If you selected Visual Studio 12 as your generator that is for Visual Studio 2013 not Visual Studio 2012. The 2 digit year and version # do not match. Visual Studio 11 is the correct generator for Visual Studio 2012. – drescherjm Dec 13 '13 at 21:10
  • Did you run `./b2 install --prefix=PREFIX`? Then set `PREFIX` as your `BOOST_ROOT` directory (it should contain an `include` and a `lib` folder) – Johannes S. Dec 14 '13 at 16:05

2 Answers2

1

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.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
0

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").
ToniBig
  • 836
  • 6
  • 21