LoginSignup
3
1

More than 5 years have passed since last update.

Boost.Logの使い方 (4. cmakeによるコンパイル)

Last updated at Posted at 2015-03-03
  1. 概略
  2. ログの収集
  3. ログの出力
  4. cmakeによるコンパイル

今回はcmakeによるコンパイルについてです。

compile with cmake

Boost.Logのコンパイルは面倒との意見が散見されます。
公式はbjamを使用するようにと書いていますが、
ここではcmakeを使用したコンパイルについて説明します。

私のサンプルコードtermoshtt/boost_log_sampleよりCMakeLists.txtを抜粋します:

CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
find_package(Boost COMPONENTS thread system log log_setup REQUIRED)
find_package(Threads)
include_directories(${Boost_INCLUDE_DIRS})

Boost.Logは1.54よりBoost本体に含まれていますので、
上述のようにcmakeで簡単に検出できます。
Boost.Threadをリンクする必要があるので、Threadsも同時にfindしておきます。

注意としてはBoost.Logのコンパイル時に動的リンクを行うためのフラグを指定する必要がある点です:

add_definitions("-DBOOST_LOG_DYN_LINK")

これであとはtarget_link_libraries${Boost_LIBRARIES}${CMAKE_THREAD_LIBS_INIT}をリンクするか、

macro(link_boost_log target)
  target_link_libraries(${target} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endmacro(link_boost_log)

のようなマクロを組めば完了です。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1