編譯好的boost庫
⑴ 如何用Visual Studio 2010編譯boost1.42庫
64位windows平台,編譯環境是VS2005,進入Visual Studio 2005 x64 Win64 Command Prompt(單純的cmd也不一定不行,我沒試)。把bjam.exe放在boost根目錄下,進入根目錄,執行:
bjam --toolset=msvc address-model=64 --with-thread stage
bjam --toolset=msvc address-model=64 --with-date_time stage
關鍵選項:「address-model=64 」
64位linux平台,使用gcc編譯。進入boost根目錄,執行:
./bjam --toolset=gcc --with-thread stage
./bjam --toolset=gcc --with-date_time stage
linux平台下倒是簡單,不過網上有篇文章介紹用如下命令編譯,不知道是多此一舉,還是適用於某些情況(非64位linux主機?)。
./bjam --toolset=gcc "-sBUILD=release <cxxflags>-m64" --with-thread stage
./bjam --toolset=gcc "-sBUILD=release <cxxflags>-m64" --with-date_time stage
唉。命令都很簡單,可浪費了我不少時間。usage根本沒寫,去看boost build的嘛,頁數n多不說,看完之後能否找到答案還是未知數。網上相關資料很少而且大多南轅北轍,只好一直搜索+嘗試。其實我只是想要個64位版本的庫而已,這應該不是啥稀罕的需求吧?
在windows平台下,編譯出來的是否是64位類庫,只有link 64位程序的時候才能發現。如果不是,link程序無法找到類庫中定義的函數或者類。linux不知道,因為我整出來直接就是64位了,我也懶得再找一台32位linux主機折騰了。
在1.37之後的boost,如果想要使用boost::thread庫,必須有boost::date_time庫。當然這件事情又一如既往很酷地沒有出現在容易看到的地方。而是讓你鏈接錯誤後再去玩抓蟲游戲。
⑵ Linux下G++怎麼編譯使用Boost庫的程序
首先把Boost庫的頭文件存放到/usr/include/boost/路徑下,再把Lib文件存放到/usr/local/lib/boost/路徑下。修改/etc/profile文件,在此文件中增加如下2個環境變數:
BOOST_INCLUDE=/usr/include/boost
export BOOST_INCLUDE
BOOST_LIB=/usr/local/lib/boost
export BOOST_LIB
寫一個如下所示的cpp文件。
//samlpe.cpp
#include <iostream>
#include <string>
#include <boost/thread.hpp>
using namespace std;
void threadRoutine(void)
{
boost::xtime time;
time.nsec = 0;
time.sec = 20;
cout << "線程函數做一些事情" << endl;
boost::thread::sleep(time);
}
int main(void)
{
string str;
cout << "輸入任意字元開始創建一個線程..." << endl;
cin >> str;
boost::thread t(&threadRoutine);
t.join();
cout << "輸入任意字元結束運行..." << endl;
cin >> str;
return 0;
}
保存。使用g++編譯,命令如下所示:
g++ -o samlpe.out samlpe.cpp -I$BOOST_INCLUDE -L$BOOST_LIB -lboost_thread-gcc-mt
其中-I參數指定Boost頭文件路徑,-L參數指定Boost庫文件路徑,-l參數指定使用線程庫名。在我使用的這個版本Boost里,到/usr /local/lib/boost路徑下,可以看到有關Boost線程庫文件,比如:libboost_thread-gcc-mt.a等。注意在用-l 參數指定庫名時把磁碟文件名前面那個lib前綴去掉就可以了。
⑶ VS2015使用boost庫,在不用修改項目屬性中include和library路徑下,還能成功編譯,如何設置
打開VS2015安裝目錄中這個文件文件D:ProgramFiles(x86)MicrosoftVisualStudio14.0VCVCWizardsdefault.vcxproj,其實是個XML文件,在default.vcxproj文件末尾的</Project>之前填加下列內容,保存即可大功告成:
<PropertyGroup>
<IncludePath>d:oost_1_60_0;$(IncludePath)</IncludePath>
<VC_LibraryPath_x86>d:oost_1_60_0VC2015_lib32;$(VC_LibraryPath_x86)</VC_LibraryPath_x86>
<VC_LibraryPath_x64>d:oost_1_60_0VC2015_lib64;$(VC_LibraryPath_x64)</VC_LibraryPath_x64>
</PropertyGroup>
其中d:oost_1_60_0是boost庫解壓路徑,該文件夾下面有boost文件夾(是boost源文件)
d:oost_1_60_0VC2015_lib32是編譯好的32位庫目錄
d:oost_1_60_0VC2015_lib64是編譯好的64位庫目錄
⑷ Linux 編譯安裝的boost庫怎麼刪除
建議你可以用電腦管家來卸載喲
電腦管家是直接把卸載同時把注冊列表也就清理了。(有的重啟後會自動刪除)
【打開電腦管家——工具箱——卸載】
卸載完之後,會有殘留,在實行【強力卸載】
⑸ 如何編譯&使用boost庫
1. 編譯
1.2. VS2005編譯boost_1_55_0
1.2.1. 使用vs2005的命令行執行:...\boost_1_55_0\bootstrap.bat
1.2.2. 編譯動態庫
bjam install stage --toolset=msvc-8.0 --stagedir="C:\Boost\boost_vc_80" link=shared runtime-link=shared threading=multi debug release
1.2.3. 編譯靜態庫
bjam install stage --toolset=msvc-8.0 --stagedir="D:\Boost\boost_vc_80" link=static runtime-link=static threading=multi debug release
各種參數詳解:
stage:表示只生成庫(dll和lib)
install:還會生出包含的頭文件
--toolset=msvc-8.0:指定編譯器版本,8.0為vs2005,其他VS類推。
--stagedir:指定編譯後存放的目錄
link:生成動態庫/靜態庫。動態庫(shared),靜態庫(static)
runtime-link:動態/靜態C/C++運行時庫,同樣有shared和static兩種組合方式。這樣共有4種組合方式,個人根據自己需要選擇。
threading:單/多線程,一般都是多線程程序,當然multi了。
debug/release:編譯版本,一般2個都需要。
2. 使用
使用靜態庫:
[cpp] view plain print?
//#define BOOST_ALL_DYN_LINK
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
使用靜態庫連接時,僅需要包含的lib為:
debug版:libboost_system-vc80-mt-gd-1_55.lib等一系列包含gd的庫。
release版本:libboost_system-vc80-mt-1_55.lib等一系列不包含gd的庫。
使用動態庫鏈接:
[cpp] view plain print?
#define BOOST_ALL_DYN_LINK
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
使用動態庫鏈接時,僅需要包含的lib為:
debug版:boost_system-vc80-mt-gd-1_55.lib,同時在生成的exe加入boost_system-vc80-mt-gd-1_55.dll
release版:boost_system-vc80-mt-1_55.lib,同時在生產的exe路徑下加入boost_system-vc80-mt-1_55.dll
⑹ 如何在XCode中配置Boost庫
話說boost在xcode5上的安裝確實很費勁,參考實驗了相當數量的文章後,終於成功在IOS模擬器上跑通了boost庫,廢話少說,上步驟
1. 下載boost.sh安裝腳本,這里選擇的是payco的安裝腳本,https://gist.github.com/payco/6880661 ,最簡單好用。也可以在csdn上我的代碼中下載,https://code.csdn.net/snippets/68017.git
2. 打開終端,su成root,命令為 sudo su,輸入密碼即可
3. 清理掉所有之前安裝的配置,尤其是在用戶目錄下的user-config.jam,必須刪除掉,之前安裝的文件也一並刪除掉,免得影響。(本人就是沒清理之前的配置,導致一直編譯不通過)
4. 把boost.sh 拷貝到/usr/local 下,運行之,會自動下載,解壓,配置,編譯boost。
5. 等待編譯安裝完畢後,顯示 Completed successfully,boost庫即安裝完畢
完成了一半,剩餘的工作就是配置xcode5,其他版本的xcode也是大同小異,沒有什麼區別的。
6. 在xcode下的target-》Building setting-> Linking-> Other Linker Flags中,添加 -lboost_system -lboost_thread,這兩項(常用的功能都包含在這2個庫中,還有其他要使用的功能,都在這里添加庫文件)
7. 在在xcode下的target-》Building setting->Search Path s 中,Header Search Path 添加/usr/local/ios/prefix/include
8. 在在xcode下的target-》Building setting->Search Paths 中,Library Search Path 添加/usr/local/ios/prefix/lib(這是給真機用的,包含arm6,arm7,arm7s等),以及/usr/local/ios/build/i386(這是給模擬器用的),基本都在一個位置上,截取一張圖好了
添加完畢之後,測試一下編譯是否成功。
在任意一個cpp文件內,添加
#include "boost/swap.hpp"
#include "boost/asio.hpp"
編譯無報錯,則順利完成boost庫在xcode5下的IOS使用編譯:)
。
