3

boost::program_options公式の指示に従って使用しようとしています: http://www.boost.org/doc/libs/1_36_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library

しかし、うまくいきません:

~/download/boost_1_36_0/libs/program_options/example> g++ -o first first.cpp /usr/lib64/libboost_program_options-mt-1_36.a

/tmp/ccNh69JH.o: 関数「main」内:
first.cpp:(.text+0xc8): `boost::program_options::options_description::options_description(std::basic_string, std::allocator > const&, unsigned int, unsigned int)' への未定義参照
/tmp/ccNh69JH.o: 関数 `std::basic_string では、std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std: :アロケーター > > > const&, bool)':                                                                     
first.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKSbIT_St11char_traitsIS3_ESaIS3_EERKSt6vectorIS7_SaIS7_EEb[std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::std:: :allocator > > > const&, bool)]+0x142): `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > への未定義参照 > const&, std::basic_string, std::allocator > const&)'
first.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKSbIT_St11char_traitsIS3_ESaIS3_EERKSt6vectorIS7_SaIS7_EEb[std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::std:: :allocator > > > const&, bool)]+0x2e9): `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > への未定義参照 > const&, std::basic_string, std::allocator > const&)'
collect2: ld が 1 つの終了ステータスを返しました

これは機能しますが、奇妙です:

g++ -o first first.cpp /usr/lib64/libboost_program_options.so.1.42.0
4

2 に答える 2

2

ヘッダーを含め、ライブラリをコンパイルし、それらへの参照を正しく追加したと仮定すると、問題を解決するための迅速な (そして怠惰な) 方法を提案できます。ソース ファイルをプロジェクトに追加し、ソリューションを検討しながら一緒にコンパイルできます。

于 2010-12-27T01:15:20.857 に答える
1

次の内容の boost.pc ファイルを作成しました。

prefix=/usr/local/boost
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: boost
Description: my boost pc file
Version: 1.57.0
Cflags: -I${includedir}
Libs: -L${libdir} -lboost_system -lboost_program_options

今、私は次のようなものを実行できます

g++ -g -O2 `pkg-config ./boost.pc --cflags --libs` -w -c main-new.cpp -o obj/main.o
g++ -g -O2 -w obj/main.o -o bin/main `pkg-config ./boost.pc --cflags --libs`

(メイクファイル経由)

于 2015-11-11T21:09:26.533 に答える