1

I have been working on a library in C++ and have run into a bit of difficulty trying to integrate boost into my project. I kept the message that boost could not be found, but on the other hand, my fellow developer using Arch had no issues.

We figured out that this is because Linux Mint (at least with the libboost-all-dev package) installs the libraries to /usr/lib/x86_64-linux-gnu which is not searched by the FindBoost module. We fixed this by creating symbolic links:

ln -s /usr/lib/x86_64-linux-gnu/libboost* /usr/lib/

What I want to know: is there a better (more acceptable) way of fixing this because when I compile major projects, I do not run into this problem.

Here is CMakeLists.txt (with some omissions)

cmake_minimum_required(VERSION 2.8)
project(testlibrary CXX)

set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)

include_directories(${Boost_INCLUDE_DIRS})

add_library(testlibrary STATIC ${SOURCE_MAIN})

target_link_libraries(testlibrary ${Boost_LIBRARIES})
Eadword
  • 160
  • 1
  • 11

1 Answers1

2

You can set the hint BOOST_LIBRARYDIR:

set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)

Alternative, you can set this when running CMake like this:

cmake -DBOOST_LIBRARYDIR="/usr/lib/x86_64-linux-gnu" <project_root>

If you just run:

cmake <project_root>

then FindBoost.cmake will look in the usual spots for your boost libaries.

See the documentation of FindBoost.cmake for your CMake version here.

huu
  • 7,032
  • 2
  • 34
  • 49
  • OK, but would that work on my partner's computer, or would they have to remove that on their end? Theirs is installed just to /user/lib/ – Eadword Apr 22 '15 at 23:56
  • The best way to handle that is to have a project level option that lets you set `BOOST_LIBRARYDIR`. – huu Apr 22 '15 at 23:58
  • do you mean set(BOOST_LIB_DIR /usr/lib/x86_64-linux-gnu) – Eadword Apr 23 '15 at 00:07
  • Disregard my comment above, there's no need for a project level option. Variables set on the command line are automatically used in the find modules. – huu Apr 23 '15 at 00:07
  • No, `BOOST_LIB_DIR` is not used at all by the find module. You have to set `BOOST_LIBRARYDIR`. If you inspect the source you'll see what's going on. – huu Apr 23 '15 at 00:09
  • How do the larger projects do it? I do not have problems compiling those when they use CMake (well, not finding boost anyway...) – Eadword Apr 23 '15 at 00:09
  • There are many ways of changing where libraries are searched for. It's possible those projects do something like set `CMAKE_LIBRARY_PATH`. You can find more useful variables in the aptly named [CMake Use Variables](http://www.cmake.org/Wiki/CMake_Useful_Variables#Environment_Variables) wiki page. – huu Apr 23 '15 at 00:17