16

私はこの問題に対する答えを高低で検索しました。私はブースト 1.48 を使用していますが、この問題を解決するために最も単純な形式に分解したため、プログラムは非常に単純です。

#include <boost/filesystem.hpp>

int main(int argc, char **argv) {
    return 0;
}

Makefile から実行される g++ コマンドは次のとおりです。

g++ -m32 -Wall -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system mapnik-test.cpp

リンク中のエラーの完全なリストは次のとおりです。

/tmp/ccIbmuee.o: In function `__static_initialization_and_destruction_0(int, int)':
mapnik-test.cpp:(.text+0x49): undefined reference to `boost::system::generic_category()'
mapnik-test.cpp:(.text+0x53): undefined reference to `boost::system::generic_category()'
mapnik-test.cpp:(.text+0x5d): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [mapnik-test] Error 1

多くの人が同じ問題に苦しんでいることがわかりましたが、ほとんどの場合、解決策は LDFLAGS で boost_system ライブラリを提供することでした。g++ コマンド ラインからわかるように、これは既に指定されています。libboost_system.a ライブラリに対して明示的にリンクしようとしても無駄でした。この苦情を持っているのは私だけですか?

4

1 に答える 1

27

Put the source file at the beginning of the command line.

Try

g++ -m32 -Wall mapnik-test.cpp -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system

The libraries should be specified only after the source file so that the linker can resolve the undefined references in the source file.

于 2012-06-28T18:43:43.783 に答える