VS2010編譯使用Boost 1 64 0

2021-07-09 04:19:17 字數 3267 閱讀 9519

(2)生成bjam.exe可執行檔案,用管理員許可權執行vs2010命令視窗

進入到到目錄e:\codedll\boost_1_64_0,執行booststrap.bat得到:

這時在目錄e:\codedll\boost_1_64_0,生成了b2.exe、bjam.exe、project-config.jam檔案。

(3)用bjam.exe編譯

執行命令

編譯靜態庫如下.

bjam stage --toolset=msvc-10.0 --without-python --build-type=complete --stagedir="e:\codedll\boost_1_64_0\bin\vc10"  link=static runtime-link=shared threading=multi debug release

編譯動態庫如下.

bjam stage --toolset=msvc-10.0 --without-python --build-type=complete --stagedir="e:\codedll\boost_1_64_0\bin\vc10" link=shared runtime-link=shared threading=multi debug release

bjam可以參考

stage表示只生成庫(dll和lib),用install的話還會生成包含標頭檔案的include目錄。

toolset指定編譯器,vs2010用msvc-10.0。

without/with表示不編譯/編譯哪些庫。

stagedir,當使用stage時用stagedir,使用install用prefix,表示編譯生成檔案的路徑。路徑的命名最好和編譯器相關,編譯管理。

link指定生成動態鏈結庫或靜態鏈結庫。生成動態鏈結庫需使用shared方式,生成靜態鏈結庫需使用static方式。

runtime-link,動態/靜態鏈結c/c++執行時庫。有shared和static兩種方式,這樣runtime-link和link一共可以產生4種組合方式。

threading,單/多執行緒編譯。

debug/release,編譯debug/release版本。一般都是程式的debug版本對應庫的debug版本,所以兩個都編譯。

bjam引數說明

--build-dir= 編譯的臨時檔案會放在builddir裡(這樣比較好管理,編譯完就可以把它刪除了) 

--stagedir= 存放編譯後庫檔案的路徑,預設是stage 

--build-type=complete 編譯所有版本,不然只會編譯一小部分版本(確切地說是相當於:variant=release, threading=multi;link=shared|static;runtime-link=shared)

variant=debug|release 決定編譯什麼版本(debug or release?) 

link=static|shared 決定使用靜態庫還是動態庫。 

threading=single|multi 決定使用單執行緒還是多執行緒庫。 

runtime-link=static|shared 決定是靜態還是動態鏈結c/c++標準庫。 

--with- 只編譯指定的庫,如輸入 

--with-regex就只編譯regex庫了。 

--show-libraries 顯示需要編譯的庫名稱

編譯全部bjam --toolset=msvc --build-dir=midfiles --stagedir=stage --build-type=complete

只編譯執行緒庫bjam --toolset=msvc --build-dir=midfiles --stagedir=stage --build-type=complete --with-thread

差不多需要一小時,編譯完成(中間會有警告)。

編譯好後,在根目錄會有個bin.v2資料夾,是編譯過程中的臨時資料夾,很大,可以手動刪除。

(4)在vs中使用boost庫

新建工程後需要把boost庫包含到工程中,右鍵選擇屬性,在vc++目錄的「包含目錄」中新增boost的根目錄,在「庫目錄」新增剛剛編譯生成的位置再加上路徑lib。

使用舉例:

#include

此時,不用包含庫檔案,boost的auto-link機制將會自動幫我們包含對應的靜態lib。也就是說,boost預設是以靜態方式鏈結的,這樣我們的工程屬性最好也設為multi-threaded (debug)。如果想使用dll動態方式鏈結,需要預先定義巨集:

#define boost_all_dyn_link

同樣,此時boost也會預設幫我們包含對應的lib。如果不想使用boost提供的auto-link機制,或者對它的自動鏈結不太放心的話(其實大可不必擔心),可以預先定義巨集:

#define boost_all_no_lib

release下

#pragma comment(lib, "boost_thread-vc100-mt-1_64.lib")

debug下

#pragma comment(lib, "boost_thread-vc100-mt-gd-1_64.lib")

另外還有乙個比較有用的巨集:

#define boost_lib_diagnostic

它可以讓vc在編譯時的output視窗中輸出程式具體鏈結了哪些boost庫以及鏈結順序。

關於boost的auto-link機制,詳細可以看看boostconfigauto_link.hpp裡的**,很容易可以讀懂,並且值得我們學習。

包含boost對應庫的標頭檔案即可使用,例如乙個多執行緒的測試:

[cpp]view plain

copy

#include "boost/thread.hpp"

#include "iostream"

using

namespace

std;  

void

threadfunc()  

intmain()  

vs2010使用boost庫,安裝

今天抽時間學習了一下boost庫,用c 做演算法,自己再去造輪子實在是浪費時間,學習boost未來工作能直接上手。比如caffe就直接使用了boost庫,這裡邊常用的 對於時間操作,字串操作,檔案操作,智慧型指標等,熟練使用這些能大大的加速演算法的開發時間。1 boost程式庫完全開發指南 深入c ...

使用VS2010編譯mod wsgi

為了在windows下使用apache發布django,檢視了文件,有兩種方式可以實現,一種是傳統方式,在apahce modules目錄下存放mod wsgi.so檔案,另一種是直接pip安裝,據文件說是比較方便,但我試了,沒有成功,不知道問題出在哪,也沒有相關中文資料,只好安裝vs2010編譯生...

VS2010靜態編譯

因為需要在其他電腦上執行.exe檔案,會有缺dll。所以需要靜態編譯生成.exe可執行檔案。在網上查詢了一下vs2010靜態編譯生成.exe的方法,有很多,試了其中一種,記錄一下,以便今後查閱。感謝提供方法的大神們!設定 1 專案 配置屬性 常規 mfc的使用 在靜態庫中使用mfc 如果有使用mfc...