Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link the static versions of the Boost libraries using CMake

Tags:

c++

boost

cmake

I've got both the static and the dynamic versions of the boost libraries in /usr/lib. Now I'd like CMake to prefer the static versions during the linkage of my executable. What can I do?

like image 247
domachine Avatar asked Jul 04 '10 20:07

domachine


People also ask

How do I add a Boost to CMake project?

For CMake, you need to add boost_program_options to the list of libraries, and IIRC this is done via SET(liblist boost_program_options) in your CMakeLists. txt .

Can I build Boost with CMake?

One of my current projects relies on Boost. Python, which requires a more recent version of Boost (1.64) than the one (1.54) provided by my Linux distribution (Ubuntu 14.04).

How do I know my Boost version?

You can check version. hpp inside Boost include dir (normally /usr/include/boost , you can use locate /boost/version. hpp or similar to get that) for BOOST_VERSION or BOOST_LIB_VERSION .


1 Answers

In your CMakeLists.txt file:

set(Boost_USE_STATIC_LIBS   ON) find_package(Boost REQUIRED ...) 

Where I have ..., you optionally put the names of the libraries you want to use, and then target_link_libraries(targetname ${Boost_LIBRARIES}) later below. If you have a fairly recent distribution of CMake, it should work exactly as advertised. I do it exactly this way in my own projects.

like image 171
greyfade Avatar answered Oct 06 '22 03:10

greyfade