天天看點

STLPort vc編譯

今天為了裝STLport,搞了很久,主要是新版本以緻搞VC6.0時,有很多要注意的。

前文: 下載下傳STLport源代碼,解壓到一個目錄,例如:F:/Program Files/STLport-5.2.1。下面都用 %STLport% 表示解壓的完全路徑。

(一)、VC6.0安裝STLport-5.2.1:

(注意:下面的步驟都在一個cmd裡操作,很簡單的原因:環境變量啊)

1、首先在…/Microsoft Visual Studio/VC98/Bin/VCVARS32.BAT中, 把%STLport%/stlport; ,(注意有英文的分号)  加入Include路徑中;把%STLport%/lib; ,加入Lib路徑中;(這裡現在%STLport%下沒有lib子目錄,先加上去,一會編譯會生成的)下面是的我:

set INCLUDE=F:/Program Files/STLport-5.2.1/stlport;%MSVCDir%/ATL/INCLUDE;%MSVCDir%/INCLUDE;%MSVCDir%/MFC/INCLUDE;%INCLUDE%

set LIB=F:/Program Files/STLport-5.2.1/lib;%MSVCDir%/LIB;%MSVCDir%/MFC/LIB;%LIB%

  2、打開cmd,運作剛才的這個VCVARS32.BAT;進入%STLport%, 運作configure --help,看一下;運作configure msvc6,正确的話,會有:

STLport Configuration Tool for Windows

Setting compiler: Microsoft Visual C++ 6.0

Setting platform: Windows XP

Done configuring STLport.

Go to build/lib folder and type "nmake clean install" to build and

install STLport to the "lib" and "bin" folders.

Go to build/test/unit folder and type nmake clean install to

build unit tests and install them in bin folder.

注意:這裡不要按網上很多人說的運作:configure -c msvc6,會有問題的,我就是被困在這兒很長時間的;這個應該是老一點的版本的方式。還有就是這個configure也不是在%STLport%/build/lib下進行的,網上都這樣講,但是%STLport%/build/lib下沒有configure啊!

3、接下來先進入%STLport%/build/lib ;執行nmake /fmsvc.mak,這個要等一段時間;之後,執行nmake /fmsvc.mak install,是一些copy動作。

4、主要是上面的步驟,後面的就是配置VC6.0了:

A、Tools -> Options -> Directories,選“Include files”,增加%STLport%/stlport,并移至頂端;不移至頂端,還是會用原來VC自帶的STL;

選“Library files”,增加%STLport%/lib,并移至頂端;

B、Project -> Settings -> C/C++, 在Category中選 “C++ Language”,

勾選”Enable exception handling”(這個最好選一下);在Category中選”Code Generation”, 在Use run-time library中選”Debug Mulithreaded”(這個Release版選” Mulithreaded”);

基本可以了,給個簡單例子,試試:(VC自帶的STL沒有slist,隻有安裝成功了,才能編譯成功)

#include <slist>

#include <iostream>

using namespace std;

int main(void)

{

slist<int> sl;

sl.push_front(11);

sl.push_front(23);

sl.push_front(39);

//列印單向連結清單元素

slist<int>::iterator i,iend;

iend=sl.end();

for(i=sl.begin(); i!=iend; i++)

cout << *i << ' ';

cout << endl;

return 0;

}

   C、上面可以編譯成功,當然你可以運程式;但是,問題來了,你在上面任意地方加一個“空格”(或是變動一下程式)重新編譯,死活都不行了,這是編譯器給的提示,你的提示應該差不多:

--------------------Configuration: main - Win32 Debug--------------------

Compiling...

main.cpp

f:/program files/stlport-5.2.1/stlport/stl/_num_put.c(494) : fatal error C1001: INTERNAL COMPILER ERROR

        (compiler file 'msc1.cpp', line 1794)

         Please choose the Technical Support command on the Visual C++

         Help menu, or open the Technical Support help file for more information

Command line warning D4028 : minimal rebuild failure, reverting to normal build

Error executing cl.exe.

Creating browse info file...

BSCMAKE: warning BK4503 : minor error in .SBR file './Debug/main.sbr' ignored

BSCMAKE: warning BK4503 : minor error in .SBR file './Debug/main.sbr' ignored

main.exe - 1 error(s), 3 warning(s)

這個是VC6.0的問題,用2005和2008都不會出現這個問題,造成這種問題的原因是編譯器配置設定的記憶體超過了限制。

解決辦法是:Project -> Settings -> C/C++, 在Category中選”Precompiled Headers”,選擇“Not using precompiled headers”就OK了,有人說這種辦法會減慢編譯速度,這個自然了,不過比起問題來,還是值得的。(各位大蝦不要說我賣弄哦,我隻是希望能幫助到更多人!)

(二)VS2005安裝STLport-5.2.1:

1、添加路徑到vcvarsall.bat,就可以了,要添加include和lib。在…Microsoft Visual Studio 8/VC/bin下有一個vcvar32.ba;其實是指向…Microsoft Visual Studio 8/Common7/Tools/ vsvars32.bat的,是以直接改它就可以了;

   主要是在“@set INCLUDE=”後面加上%STLport%/stlport; ,(注意有英文的分号)  加入Include路徑中;在@set LIB=後面加上%STLport%/lib;(這裡現在%STLport%下沒有lib子目錄,先加上去,一會編譯會生成的)。

後面的和上面VC6.0安裝差不多,寫簡單一點:

2、進入%STLport%,configure --help 可以看到相關的編譯器的設定:configure msvc8

3、進入%STLport%/build/lib, 執行nmake /fmsvc.mak

4、接下來:nmake /fmsvc.mak install

5、接下來把上面%STLport%/stlport、%STLport%/lib添加到vs2005的vc目錄路徑,而且放在最上面

6、可以編譯成功上面的那個例子了,但是,運作的話:會說“丢失 stlported5.2.dll”;是以,還需要把%STLport%/bin裡面的所有檔案都複制到vc的bin檔案夾目錄下; (在VC6.0中不需要此步)

(三)、VS2008安裝stlport-5.2.1的過程 (參照VS2005安裝)

1、解壓到C:/STLport-5.2.1

2、添加路徑後,打開vs2008的cmd的prompt,進入C:/STLport-5.2.1/STLport-5.2.1

3、configure msvc9

4、進入C:/STLport-5.2.1/STLport-5.2.1/build/lib

5、nmake -clean

6、nmake install

繼續閱讀