1.gcc版本>3.2
2.Yum 的 boost 和boost-python文件很小,好像不行。所以編譯安裝。
3.boost庫分為三種:無需編譯;單獨編譯;部分編譯。python需要單獨編譯。
4.使用無需編譯庫的一個例子:
include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> int main() { using namespace boost::lambda; typedef std::istream_iterator<int> in; std::for_each( in(std::cin), in(), std::cout << (_1 * 3) << " " ); }
Copy the text of this program into a file called example.cpp. Now, in the directory where you saved example.cpp, issue the following command:
c++ -I path/to/boost_1_54_0 example.cpp -o example
To test the result, type:
echo 1 2 3 | ./example
5.編譯中有warning沒有關系,但不能有error.
6.安裝單獨編譯子庫。注意,工作目錄。工作目錄決定了b2 install的安裝內容。
-
-
$ cd path/to/boost_1_54_0 $ ./bootstrap.sh --help 查看配置選項
- 使用合適的配置選項運行./boostrap.sh
- 運行./b2 install安裝
- 以上方法可以安裝全部,選擇合適參數可以只安裝部分庫(--show-libraries and --with-libraries=library-name-list),這種方法跟7安裝部分庫有什么不同?
-
7.安裝定制庫
-
- 如果使用非系統默認的編譯器,需要使用boos.built編譯。
- 如果想要使用非標准的編譯方法,也需要使用boost.build.
- boost.build是用於開發測試安裝軟件的一個文本系統。安裝方法boost.build的方法:
-
- Go to the directory tools/build/v2/.
- Run bootstrap.sh
- Run b2 install --prefix=PREFIX where PREFIX is the directory where you want Boost.Build to be installed
- Add PREFIX/bin to your PATH environment variable.
-
試運行一個例子,會產生可執行代碼。Copy
to a different directory, then change to that directory and run:PREFIX
/share/boost-build/examples/helloPREFIX
/bin/b2
-
- 安裝完畢boost.build后,回到boost根目錄。運行
b2 --build-dir=build-directorytoolset=toolset-name stage 比如:
$ cd ~/boost_1_54_0 $ b2 --build-dir=/tmp/build-boost toolset=gcc stage :會產生一個靜態共享非調試多線程的boost庫。如果想要產生所有類型的boost庫,使用built-type=complete。 statge目標會將庫二進制文件放在stage/lib中,可以使用stage-dir=...指定。查看幫助 b2 --help.為了限制時間可以:
- reviewing the list of library names with --show-libraries
- limiting which libraries get built with the --with-library-name or --without-library-name options
- choosing a specific build variant by adding release or debug to the command line.
- 如果沒有安裝python,那么boost.python會不報錯的跳過,但是會產生一個警告。
- 如果有zip bzzip2c錯誤,那么是因為沒有安裝先關的庫,bzip2需要安裝bz2庫;zip是z庫。這些錯誤無關緊要,但是其他error需要關注
- 如果仿佛看起來找不到編譯器連接器,考慮建議里一個user-config.jam文件,如果不是這個問題,咨詢郵件列表。
8.一個用Link例子。
9.編譯好的庫的命名規則。xxx.a xxx.so.
10.如果你的程序Link到了一個庫,那么運行的時候,需要設定好環境變量,以便能夠在運行時找到動態庫。LD_LIBRARY_PATH。
$ VARIABLE_NAME=path/to/lib/directory:${VARIABLE_NAME} $ export VARIABLE_NAME