當前位置:首頁 » 編程軟體 » boost編譯linux

boost編譯linux

發布時間: 2022-07-17 16:18:48

❶ Boost庫 linux下GCC編譯,直接拷出Lib和inc到window下能用嗎

不可以的
在linux下獲取到的只是linux可以用的庫
用Mingwin的才可以在windows上用
靜態庫看起來是一樣的
都是.a
不過本質是不同的
動態庫
區別更明顯些
linux是.so
而windows是.dll

❷ 如何編譯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下eclipse使用boost asio進行網路開發

linux下boost asio並行開發:
1.三種使用方式
1)single thread && single io_service, 最簡單, 性能最一般
2)multithread && single io_service
3)io_service per thread. multi io_service.
這三個性能是依次遞增的。
2.在使用ASIO時,io_servie應該盡量多,這樣可以使其epoll_wait佔用的時間片最多,這樣可以最大限度的響應IO事件,降低響應時延。但是每個io_servie::run佔用一個線程,所以io_servie最佳應該和CPU的核數相同。

3.io_service是一個工作隊列的模型。在使用過程中一般有如下幾個需要注意的地方:
run函數在io事件完成後會退出,導致後續基於該對象的非同步io任務無法執行。
由於io_service並不會主動常見調度線程,需要我們手動分配,常見的方式是給其分配一個線程,然後執行run函數。但run函數在io事件完成後會退出,線程會終止,後續基於該對象的非同步io任務無法得到調度。
解決這個問題的方法是通過一個asio::io_service::work對象來守護io_service。這樣,即使所有io任務都執行完成,也不會退出,繼續等待新的io任務。
boost::asio::io_service io;
boost::asio::io_service::work work(io);
io.run();

❹ 在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內核程序使用C++時可以使用BOOST,STL類似的函數庫么

當然可以,c++是跨平台的,,c++可以用boost,但是得在linux下邊重新編譯,而stl這個東西可以直接用的。你可以在linux下邊找到stl的庫函數的。boost編譯完了,得把相應的so加到g++路徑或者env變數路徑裡面。想學習了解更多linux知識,請關注《linux就該這么學》官網。

❻ 如何在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程序。

❼ 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前綴去掉就可以了。

熱點內容
db2新建資料庫 發布:2024-09-08 08:10:19 瀏覽:170
頻率計源碼 發布:2024-09-08 07:40:26 瀏覽:778
奧迪a6哪個配置帶後排加熱 發布:2024-09-08 07:06:32 瀏覽:100
linux修改apache埠 發布:2024-09-08 07:05:49 瀏覽:208
有多少個不同的密碼子 發布:2024-09-08 07:00:46 瀏覽:566
linux搭建mysql伺服器配置 發布:2024-09-08 06:50:02 瀏覽:995
加上www不能訪問 發布:2024-09-08 06:39:52 瀏覽:811
銀行支付密碼器怎麼用 發布:2024-09-08 06:39:52 瀏覽:513
蘋果手機清理瀏覽器緩存怎麼清理緩存 發布:2024-09-08 06:31:32 瀏覽:554
雲伺服器的優點與缺點 發布:2024-09-08 06:30:34 瀏覽:734