boostのコンパイルが通らない

C++のライブラリのboostを使ったときにコンパイルしたらエラーが起きたのでメモです。

エラーが起きるまで

homebrewでboostをインストールし、コードを以下のようにコンパイル

g++ -std=c++11 test.cpp

すると以下のようなエラーが発生した。

エラー

Undefined symbols for architecture x86_64:
  "boost::system::generic_category()", referenced from:
      boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in test-50e82c.o
      boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in test-50e82c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

対処法

コンパイル時に以下のオプションをつける。

-lboost_system