轉自:http://blog.csdn.net/hejianhua/article/details/12910409
我在poco官網上下載了其支持windows平臺的源代碼,編譯完成後,它就自動和vs掛鉤了,在vs系列的IDE上都很容易用。但是現在我想用codeblocks(windows下用),我在工程中bin,lib,.h的的路徑都添加好了,可是編譯不能通過,而使用同樣的方法在vs中就完全沒有問題,爲什麼呢?鬱悶!
我在windows下都用不起,更別說linux了,所以請大家先幫我解決下這個問題吧。這個問題,同問ace,ice,它們都能在vs下搞,但是放在codeblocks上就要現怪相!我有點白,大家說詳細點,感謝~
------解決方案--------------------------------------------------------
第一步:編譯第三方庫,得到頭文件和庫,例如路徑關係:
D:\MyLib\include
D:\MyLib\lib
在include中放頭文件,在lib中放置庫文件。
第二步:創建全局變量,菜單:Settings > Global variables, New一個新的,選名字,例如MYLIB
Base: /usr/local/ACE/ACE_wrappers
include: $(BASE)\ace
lib: $(BASE)\lib
第三步:設置工程搜索路徑,菜單:Project > build options > Search directories
Compiler: $(#MYLIB) // 解釋:因爲文件中包含的是 #include "ace/tas.h",所以搜索路徑不需要Compiler: $(#MYLIB.ace)
Linker: $(#MYLIB.lib)
即可使用。
如果不想添加全局變量,則第三步時,使用絕對路徑,來分別設置頭文件和庫文件的查找路徑。
------解決方案--------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
作者:朱金燦
來源:http://blog.csdn.net/clever101
首先請先編譯或安裝boost庫,使用CodeBlocks編譯boost庫具體見:Boost庫在CodeBlocks環境下的編譯。
以下內容主要翻譯自:BoostWindows Quick Ref,我所用的編譯環境爲Win 7家庭版,CodeBlocks V10.05, mingw32 v4.4.1,boostv1.42
1. 爲boost庫創建一個CodeBlocks全局變量
1)打開“Settings”菜單——>"Global variables..."菜單項,彈出如下對話框,單擊下圖的對話框上的New按鈕,
2) 在彈出的對話框上輸入你要新建的全部變量名,例如boost,如下圖:
3)設置全局變量的base目錄、lib目錄和include目錄,具體如下圖:
Base目錄爲你的boost安裝目錄,也是你在編譯boost庫的—prefix選項的參數值,如:
你的bjam命令爲:
bjam install--toolset=gcc--prefix="C:\zjc\PluginFramework\boost_1_42_0"--build-type=complete
那麼base目錄爲C:\zjc\PluginFramework\boost_1_42_0
Include和lib目錄很容易理解,就是boost庫的頭文件和庫文件所在的目錄。
現在我們使用一下這個全局變量,
1. CodeBlocks新建一個控制檯工程TestConsole,敲入如下代碼:
- <SPAN style="FONT-SIZE: 18px"> #include <stdlib.h>
- #include <iostream>
- using std::cout;
- using std::wcout;
- using std::endl;
- #include <string>
- using std::string;
- using std::wstring;
- #include <boost/algorithm/string.hpp>
- #include <boost/filesystem/path.hpp>
- #include "boost/filesystem/operations.hpp"
- #include <boost/format.hpp>
- int main()
- {
- // ANSI字符的格式化
- cout << boost::format( "%1% %2%" ) % "Hell" % "Low" <<endl;
- string s1 = boost::str( boost::format( "%2% %1%" ) % "Hell" % "Low" );
- cout << s1 << endl;
- // UNICODE字符的格式化
- wcout << boost::wformat( L"%s %X" ) % L"-1 is" % -1 << endl;
- wstring s2 = boost::str( boost::wformat( L"%2$s %1$.2f" ) % 3.141592 % L"Version" );
- wcout << s2 << endl;
- // 獲取應用程序所在目錄(ANSI字符),注意是boost::filesystem::path
- string AnsiPath = boost::filesystem::initial_path<boost::filesystem::path>().string();
- cout<<AnsiPath<<endl;
- // 獲取應用程序所在目錄(UNICODE字符),注意是boost::filesystem::wpath
- wstring UnicodePath = boost::filesystem::initial_path<boost::filesystem::wpath>().string();
- wcout<<UnicodePath<<endl;
- system("PAUSE");
- return 0;
- }
- </SPAN>
- <span style="font-size:18px"> #include <stdlib.h>
- #include <iostream>
- using std::cout;
- using std::wcout;
- using std::endl;
- #include <string>
- using std::string;
- using std::wstring;
- #include <boost/algorithm/string.hpp>
- #include <boost/filesystem/path.hpp>
- #include "boost/filesystem/operations.hpp"
- #include <boost/format.hpp>
- int main()
- {
- // ANSI字符的格式化
- cout << boost::format( "%1% %2%" ) % "Hell" % "Low" <<endl;
- string s1 = boost::str( boost::format( "%2% %1%" ) % "Hell" % "Low" );
- cout << s1 << endl;
- // UNICODE字符的格式化
- wcout << boost::wformat( L"%s %X" ) % L"-1 is" % -1 << endl;
- wstring s2 = boost::str( boost::wformat( L"%2$s %1$.2f" ) % 3.141592 % L"Version" );
- wcout << s2 << endl;
- // 獲取應用程序所在目錄(ANSI字符),注意是boost::filesystem::path
- string AnsiPath = boost::filesystem::initial_path<boost::filesystem::path>().string();
- cout<<AnsiPath<<endl;
- // 獲取應用程序所在目錄(UNICODE字符),注意是boost::filesystem::wpath
- wstring UnicodePath = boost::filesystem::initial_path<boost::filesystem::wpath>().string();
- wcout<<UnicodePath<<endl;
- system("PAUSE");
- return 0;
- }
- </span>
2. 在工程樹節點上右鍵單擊,在彈出的右鍵菜單上單擊Build Option…菜單項,如下圖:
3.在彈出的對話框中選擇Search directories選項卡,然後單擊對話框中的add按鈕,在彈出的對話框中輸入:$(#boost),具體如下圖:
看到這,你可能覺得比較熟悉,這個CodeBlocks全局變量不相當於一個操作系統環境變量嗎?是的,它起的正是這個作用。
4.選擇“Linker setting”選項卡,填入你的工程要鏈接到到的具體的boost庫,具體如下圖:
一個小小的問題,在使用boost庫時只需在定義了BOOST_ALL_DYN_LINK宏,同時指定了庫文件所在的文件夾就能實現自動鏈接而不必指定要鏈接到的具體庫,這個我在VS環境下已經多次使用過,但我在CodeBlocks下定義了BOOST_ALL_DYN_LINK,如下圖:
但是還是得指定鏈接到的具體庫,這是爲什麼呢?知道的大俠請具體指點下。
參考文獻: