0

I'm writing a C++ program for which I would like to use some functionality from Boost (not just the header-only modules), and which I'm distributing in source form. I'd like it to work on as many operating systems as possible, but take Linux for the sake of being concrete. (I'm more used to Windows, but there I can fall back on shipping a binary, as long as Boost is amenable to static linking.)

Right now, I'm shipping a simple handwritten makefile, so the procedure for compiling the program is just make. However, I'm given to understand this no longer works when you bring Boost into the equation, because you can't know what version (if any) will be available on the user's machine, or where the header and library files will be located, and that one should instead use a build system such as autotools or CMake.

Is this correct? If so, which build system should be used if the highest priority is reliability (i.e. maximizing the probability that it will work when a user tries to compile and install the program)?

(I'm also planning to use GMP, if that makes a difference.)

rwallace
  • 31,405
  • 40
  • 123
  • 242
  • 2
    I can't reply to your question because I don't know a lot of tools. But I know cmake, and I can tell you that CMake will fit your need, but I can't tell you if this tool will "maximize the probability". – Adrien BARRAL Aug 22 '12 at 13:42
  • 2
    I'd recommend you to use CMake too. – arrowd Aug 22 '12 at 16:25

1 Answers1

3

Compiling a program that uses Boost statically is quite simple in CMake. Using the FindBoost module handles it for you.

An example CMakeLists.txt file for a program that uses program_options statically:

cmake_minimum_required(VERSION 2.8)
project(myproj)

set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.40 REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})

add_executable(myexe source_file.cpp)
target_link_libraries(myexe ${Boost_LIBRARIES})
Silas Parker
  • 8,017
  • 1
  • 28
  • 43