2013-01-06 14 views
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不能提振正則表達式鏈接到MinGW的

升壓: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 

如果我把的確切名稱*某文件的結果是cannot find -llibboost_regex-mgw47-mt-1_52.a

甚至整個路徑是-ld:\boost\stage\lib\libboost_regex-mgw47-mt-1_52.a不起作用。無論我在-l之後放置的效果如何,

回答

1

正如你可以看到here您必須使用(-l隨後命名庫中取出的lib preffix和延伸.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:有一件事我親自做的是使用--layout=tagged建設的推動作用。這使得庫的名稱更易於管理(在這種情況下爲libboost_regex-mt.a)。