VS2010使用STLPort
STLport的下載地址
http://sourceforge.net/projects/stlport/
下載后销斟,解壓出文件影晓。我的目錄是 D:\STLport-5.2.1 语淘。
右鍵計(jì)算機(jī)捅厂,屬性,高級(jí)系統(tǒng)設(shè)置象颖,環(huán)境,系統(tǒng)變量,編輯Path變量镇饺,添加;C:\Program Files\Microsoft Visual Studio 10.0\VC\bin。(我的路徑是這樣琢歇,分號(hào)是分隔符)兰怠,確定梦鉴。。
然后在 C:\Program Files\Microsoft Visual Studio 10.0\VC\bin 目錄揭保,編輯 vcvars32.bat 肥橙。
找到下面的一段,主要是添加STLport的include和lib路徑秸侣,我的分別是 D:\STLport-5.2.1\stlport和D:\STLport-5.2.1\build\lib存筏,注意分號(hào),它是分隔符味榛。
@rem INCLUDE
@rem -------
@if exist "%VCINSTALLDIR%ATLMFC\INCLUDE" set INCLUDE=%VCINSTALLDIR%ATLMFC\INCLUDE;%INCLUDE%;D:\STLport-5.2.1\stlport
@if exist "%VCINSTALLDIR%INCLUDE" set INCLUDE=%VCINSTALLDIR%INCLUDE;%INCLUDE%
@rem LIB
@rem ---
@if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIB=%VCINSTALLDIR%ATLMFC\LIB;%LIB%;D:\STLport-5.2.1\build\lib
@if exist "%VCINSTALLDIR%LIB" set LIB=%VCINSTALLDIR%LIB;%LIB%
保存之后椭坚,雙擊 vcvars32.bat ,使我們的設(shè)置生效搏色。
在 C:\Program Files\Microsoft Visual Studio 10.0\VC 目錄下善茎,運(yùn)行 vcvarsall.bat 。
在 D:\STLport-5.2.1\stlport\stl 目錄频轿,編輯 _cstdlib.h垂涯。
將第158行的
inline _STLP_LONG_LONG? abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; }
這一行改為如下三行。(就是多了個(gè)if判斷航邢。)
#if !defined(_STLP_MSVC) || (_STLP_MSVC < 1600)
inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; }
#endif
保存耕赘。
打開(kāi)開(kāi)始菜單的Microsoft Visual Studio 2010下的Visual Studio Tools中Visual Studio Command Prompt(2010)。
切換到STLport的目錄下
cd D:\STLport-5.2.1
d:
進(jìn)行配置膳殷,可以通過(guò) configure --help查看支持哪些配置操骡。
configure msvc9
切換到lib目錄
cd build/lib
然后是
nmake /f msvc.mak clean install
我測(cè)試的效果如下:
Setting environment for using Microsoft Visual Studio 2010 x86 tools
C:\Program Files\Microsoft Visual Studio 10.0\VC>cd D:\STLport-5.2.1
C:\Program Files\Microsoft Visual Studio 10.0\VC>d:
D:\STLport-5.2.1>configure msvc9
STLport Configuration Tool for Windows
Setting compiler: Microsoft Visual C++ 2008
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.
D:\STLport-5.2.1>cd build/lib
D:\STLport-5.2.1\build\lib>nmake /f msvc.mak clean install
————
等了幾分鐘就安裝好了。
在D:\STLport-5.2.1目錄多了幾個(gè)文件夾赚窃,如bin和lib等册招。
把 D:\STLport-5.2.1\bin下 stlport.5.2.dll,stlportd.5.2.dll考榨,stlportstld.5.2.dll跨细,復(fù)制到 C:\Program Files\Microsoft Visual Studio 10.0\VC\bin 目錄下,這樣vc就能找到它了河质。
設(shè)置vc工程的include和lib目錄了冀惭。
VS2010菜單,View掀鹅,Property Manager散休,Debug|Win32,雙擊Microsoft.Cpp.Win32.user,Common Properties,VC++ directories乐尊。
在 Include Directories 下添加 D:\STLport-5.2.1\stlport 戚丸。
在 Library Directories 下添加 D:\STLport-5.2.1\lib 。
確定,通過(guò)這樣的設(shè)置限府,以后建立的工程的VC++ Directories都有這些東西夺颤,就不用那么麻煩每個(gè)工程都進(jìn)行設(shè)置了。
測(cè)試程序胁勺。
/*功能世澜,Win7下vs2010使用STLport。
日期署穗,2012年8月24日?星期五
環(huán)境寥裂,win7-32-vs2010
*/
#include?
#include?
usingnamespacestd;
intmain()
{
//?crope是用來(lái)存儲(chǔ)char字符的容器
crope?crope1("Hello,");
crope?crope2("STLport!");
cout?<<?crope1?+?crope2?<<?endl;
system("pause");
return0;
}
/*
輸出效果:
Hello,STLport!
請(qǐng)按任意鍵繼續(xù).?.?.
*/
VS2010編輯boost庫(kù)
(1)首先下載源代碼:http://softlayer-dal.dl.sourceforge.NET/project/boost/boost/1.56.0/boost_1_56_0.zip
解壓到某個(gè)目錄,我解壓到了D盤根目錄:D:\boost_1_56_0
(2)生成bjam.exe可執(zhí)行文件
用VS2010命令行
進(jìn)入到到目錄D:\boost_1_56_0案疲,運(yùn)行booststrap.bat得到:
這時(shí)在目錄D:\boost_1_56_0生成了b2.exe封恰、bjam.exe、project-config.jam文件褐啡。
(3)用bjam.exe編譯
運(yùn)行命令bjam stage --without-Python--toolset=msvc-10.0 --build-type=complete --stagedir="D:\boost_1_56_0\bin\vc10" ?link=static runtime-link=shared threading=multi debug release
bjam可以參考http://blog.chinaunix.net/uid-22301538-id-3158997.html
stage表示只生成庫(kù)(dll和lib)诺舔,用install的話還會(huì)生成包含頭文件的include目錄。
toolset指定編譯器春贸,VS2010用msvc-10.0混萝。
without/with表示不編譯/編譯哪些庫(kù)。
stagedir萍恕,當(dāng)使用stage時(shí)用stagedir,使用install用prefix车要,表示編譯生成文件的路徑允粤。路徑的命名最好和編譯器相關(guān),編譯管理翼岁。
link指定生成動(dòng)態(tài)鏈接庫(kù)或靜態(tài)鏈接庫(kù)类垫。生成動(dòng)態(tài)鏈接庫(kù)需使用shared方式,生成靜態(tài)鏈接庫(kù)需使用static方式琅坡。
runtime-link悉患,動(dòng)態(tài)/靜態(tài)鏈接C/C++運(yùn)行時(shí)庫(kù)。有shared和static兩種方式榆俺,這樣runtime-link和link一共可以產(chǎn)生4種組合方式售躁。
threading,單/多線程編譯茴晋。
debug/release陪捷,編譯debug/release版本。一般都是程序的debug版本對(duì)應(yīng)庫(kù)的debug版本诺擅,所以兩個(gè)都編譯市袖。
差不多需要一小時(shí),編譯完成(中間會(huì)有警告)烁涌。
編譯好后苍碟,在根目錄會(huì)有個(gè)bin.v2文件夾酒觅,是編譯過(guò)程中的臨時(shí)文件夾,很大微峰,可以手動(dòng)刪除舷丹。
(4)在VS中使用Boost庫(kù)
新建工程后需要把Boost庫(kù)包含到工程中,右鍵選擇屬性县忌,在VC++目錄的“包含目錄”中添加Boost的根目錄掂榔,在“庫(kù)目錄”添加剛剛編譯生成的位置再加上路徑lib。
之后包好頭文件即可使用症杏,例如一個(gè)多線程的測(cè)試:
[cpp]view plaincopy
#include?"boost/thread.hpp"
#include?"iostream"
usingnamespacestd;
voidthreadFunc()
{
cout?<<"This?is?a?thread?function"<<?endl;
}
intmain()
{
boost::function?func(threadFunc);
boost::threadt(func);
t.join();
return0;
}