boost庫編譯選項Linux
❶ 編寫linux內核程序使用C++時 可以使用BOOST,STL類似的函數庫么
當然可以,c++是跨平台的,,c++可以用boost ,但是得在linux 下邊重新編譯,而stl 這個東西可以直接用的。你可以在linux 下邊找到stl 的庫函數的。
boost 編譯完了,得把相應的so 加到 g+ +路徑或者env 變數路徑裡面。。
❷ 如何編譯boost linux
linux平台下要編譯安裝除gcc和gcc-c++之外,還需要兩個開發庫:bzip2-devel 和python-devel,因此在安裝前應該先保證這兩個庫已經安裝:
#yum install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel -y
然後是去官網下載源碼包,按照如下步驟:
#tar xvzf boost_1_50_0.tar.gz
進入boost_1_50_0目錄:
#cd boost_1_50_0
然後是編譯安裝,boost源碼包中有配置腳本,直接用就可以:
#sh ./bootstrap.sh
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
./b2
To adjust configuration, edit 'project-config.jam'.
Further information:
- Command line help:
./b2 --help
- Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html
- Boost.Build documentation:
http://www.boost.org/boost-build2/doc/html/index.html
接下來就是編譯,重點關注是否編譯成功:
#./b2
❸ 在linux上運行boost庫的問題
我系統是ubuntukylin14.04
然後今天去BOOST下了最新版的boost1.57版
下載下來的壓縮文件我解壓到/opt目錄下即/opt/boost_1_57_0
然後
cd /opt/boost_1_57_0;
./boststrap;
./b2
這里b2命令執行完成後顯示:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/opt/boost_1_57_0
The following directory should be added to linker library paths:
/opt/boost_1_57_0/stage/lib
然後我找了一段例子
C/C++ code?
1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<boost/bind.hpp>
using namespace std;
using namespace boost;
int fun(int x,int y){return x+y;}
int main(){
int m=1;int n=2;
cout<<boost::bind(fun,_1,_2)(m,n)<<endl;
return 0;
}
用g++編譯的時候提示
bst.cxx:2:31: fatal error: boost/bind.hpp: 沒有那個文件或目錄
#include<boost/bind.hpp>
^
compilation terminated.
❹ 如何在linux上使用boost:thread-C/C++
首先需要安裝boost,步驟如下:
下載到boost_1_49_0.tar.bz2 (當然,其他壓縮格式也可以)後,可以把它放在用戶目錄下,即:~/
解壓縮:tar -jxvf boost_1_49_0.tar.bz2
這樣,出現文件夾:~/boost_1_49_0
然後進入:$ cd boost_1_49_0
你會發現有一個sh命令:bootstrap.sh
運行它:$ ./bootstrap.sh (boost自己的get start文檔中說設置參數 --prefix=dir 其中dir為你想指定的安裝文件夾,我建議就不用加這個參數,它會默認安裝到/usr/local)
結束後出現一個可執行文件: ~/boost_1_49_0/b2
運行這個文件: $ sudo ./b2 install (Ubuntu用戶千萬別忘了加sudo,不然安裝後將無法完全使用)
編譯安裝時間比較長,根據不同機器的情況20~40分鍾。結束後即安裝完畢。
boost::thread的使用
#include<boost/thread.hpp>
#include<iostream>
voidtask1(){
//dostuff
std::cout<<"Thisistask1!"<<std::endl;
}
voidtask2(){
//dostuff
std::cout<<"Thisistask2!"<<std::endl;
}
intmain(intargc,char**argv){
usingnamespaceboost;
threadthread_1=thread(task1);
threadthread_2=thread(task2);
//dootherstuff
thread_2.join();
thread_1.join();
return0;
}
編譯時的命令為:
$ g++ -I./inlcude -L./lib example.cpp -lboost_thread -o example
編譯之後會出現一個 example 的可執行文件,可以運行:./example , 結果顯示:
This is task2!
This is task1!
可能你在運行時會出現這樣的錯誤:error while loading shared libraries: libboost_thread.so.1.49.0: cannot open shared object file: No such file or directory
這是因為要用到的庫不在默認的環境變數里,可以使用下面的命令添加:
$ sudo ldconfig /usr/local/lib
添加後,再執行./example,這樣你就完成了你的第一個boost::thread程序。
❺ Boost庫 Linux下GCC編譯,直接拷出Lib和inc到window下能用嗎
不可以的
在linux下獲取到的只是linux可以用的庫
用Mingwin的才可以在windows上用
靜態庫看起來是一樣的
都是.a
不過本質是不同的
動態庫
區別更明顯些
linux是.so
而windows是.dll
❻ linux CentOS7系統如何升級boost庫
直接重新下載安裝即可
1.下載 boost
2. 將文件解壓在/usr/local/目錄下
3. 進入/usr/local/boost/ 目錄, 在terminal中輸入
./bootstrap.sh
4.進入/usr/local/boost/ 目錄,在terminal中輸入
sudo ./bjam --layout=versioned --build-type=complete --toolset=gcc install
5.添加環境變數(剛改完要重啟或者注銷一下來更新剛修改過的環境變數)
兩種方法:
(1)修改/etc/profie文件 末尾添加
export BOOST_INCLUDE=/usr/local/include/boost
export BOOST_LIB=/usr/local/lib
(2)在/etc/profile.d/ 中新建一個shell文件boost.sh
#!/bin/sh
export BOOST_INCLUDE=/usr/local/include/boost
export BOOST_LIB=/usr/local/lib