2

(Linux Debian Squeeze g++4.4 で) 個別にコンパイルされた Boost (1.54.0) ライブラリを使用したい:

  • ブーストクロノ
  • Boost.Context
  • Boost.Filesystem
  • Boost.GraphParallel
  • Boost.IOStreams
  • Boost.ロケール
  • Boost.MPI
  • Boost.ProgramOptions
  • Boost.Python
  • Boost.Regex
  • Boost.Serialization
  • Boost.Signals
  • ブーストシステム
  • ブーストスレッド
  • ブーストタイマー
  • ブーストウェーブ

これを行うために、Easy Build and Installに従って、ターミナルに入力しました

$ cd path/to/boost_1_54_0
$ ./bootstrap.sh --prefix=~/boost
$ ./b2 install

その結果、2 つのフォルダincludelibが に作成されました~/boost。ファイル~/boost/libがあります:

libboost_name.a
libboost_name.so
libboost_name.so.1.54.0

各ブースト ライブラリ。

次に、いくつかのライブラリ (正規表現など) を test.cpp ファイルに含めます。

#include<boost/regex.hpp>   //may be also chrono, filesystem or whatever

~/boost/lib で正規表現ライブラリを検索するようにコンパイラに指示します

$ g++ -I path/to/boost_1_54_0 test.cpp -o test -L~/boost/lib -lboost_regex

しかし、これはコンパイルエラーになります:

test.cpp:(.text+0x49): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x53): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x5d): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status

なにが問題ですか?stagemy にはフォルダーがなく、 Easy Build and Installに記載されて~/boostいるようなものもありません。これがレゾン?libboost_regex-gcc34-mt-d-1_36.a

これがtest.cppの内容です

//I need a general solution/idea that works for any of these libraries
#include <boost/regex.hpp>
//#include <boost/chrono.hpp>
//#include <boost/filesystem.hpp>
//#include<boost/some-other-separately-compiled-library>

int main()
{
}

個別にビルドする必要があるすべての Boost ライブラリで機能する Boost ライブラリをリンクする簡単な方法はありますか?

4

2 に答える 2

1

Boost の設定に問題があります。Boost 内の特定のライブラリは、必要に応じて正しく解決する必要があります。

Debian / Ubuntu システムでは、ヘッダーとライブラリが標準の場所にあり、出荷時に Boost を使用しているため、次g++の 1 つのコマンドで呼び出すことができ-lfooます。

edd@max:/tmp$ g++ -o boost_re_ex boost_regex_credit_card_ex.cpp -lboost_regex
edd@max:/tmp$ ./boost_re_ex 
validate_card_format("0000111122223333") returned 0
validate_card_format("0000 1111 2222 3333") returned 1
validate_card_format("0000-1111-2222-3333") returned 1
validate_card_format("000-1111-2222-3333") returned 0
machine_readable_card_number("0000111122223333") returned 0000111122223333
machine_readable_card_number("0000 1111 2222 3333") returned 0000111122223333
machine_readable_card_number("0000-1111-2222-3333") returned 0000111122223333
machine_readable_card_number("000-1111-2222-3333") returned 000111122223333
human_readable_card_number("0000111122223333") returned 0000-1111-2222-3333
human_readable_card_number("0000 1111 2222 3333") returned 0000-1111-2222-3333
human_readable_card_number("0000-1111-2222-3333") returned 0000-1111-2222-3333
human_readable_card_number("000-1111-2222-3333") returned 000-1111-2222-3333
edd@max:/tmp$ 

これは、Boost の「クレジット カード」サンプル ファイル を Web サイトから直接使用しています。

于 2013-09-14T13:25:56.543 に答える