0

私のmingwコンパイラ:http ://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.2/32-bit/threads-posix/sjlj/x32-4.7.2-release-posix-sjlj- rev6.7z

ブースト:http ://sourceforge.net/projects/boost/files/boost/1.52.0/boost_1_52_0.7z

(両方ともD:ドライブ)

コード:

#include <boost\regex.hpp>
int main() {
  boost::regex reg("[a-z]+");
}

コマンドライン:

SET PATH=%PATH%;D:\mingw\bin;D:\mingw\include
g++ -I "d:\mingw\include" -I "d:\boost" -Os -s -o test.exe test.cpp -std=c++11 -static -L "D:\boost\stage\lib" -lboost_regex

d:\boost\stage\libディレクトリには。がありlibboost_regex-mgw47-mt-1_52.aます。

そして、プロセスは戻ります:

d:/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lboost_regex
collect2.exe: error: ld returned 1 exit status

* .aファイルの正確な名前を入力すると、結果は次のようになります。cannot find -llibboost_regex-mgw47-mt-1_52.a

-ld:\boost\stage\lib\libboost_regex-mgw47-mt-1_52.a動作しないパス全体ですら。後に置いたものは何でも-l同じ効果があります。

4

1 に答える 1

4

ここでわかるように、次のいずれかを使用する必要があります(-lその後に、ライブラリの名前が続き、libプレフィックスと拡張子.aが削除されます)。

g++ -I "d:\mingw\include" -I "d:\boost" -Os -s -o test.exe test.cpp -std=c++11 -static -L "D:\boost\stage\lib" -lboost_regex-mgw47-mt-1_52

または(を使用しないライブラリのフルパス-l):

g++ -I "d:\mingw\include" -I "d:\boost" -Os -s -o test.exe test.cpp -std=c++11 -static D:/boost/stage/lib/libboost_regex-mgw47-mt-1_52.a

PS:私が個人的に行っていることの1つは、を使用してブーストをビルドすること--layout=taggedです。これにより、ライブラリの名前がはるかに管理しやすくなります(この場合libboost_regex-mt.a)。

于 2013-01-06T07:08:55.160 に答える