|
windows下編譯wxwidgets、boost並加入到codeblocks路徑中去 (visual c++ 2008/mingw32)
編譯wxwidgets
1、到官網下載源碼包(MSW),安裝到 X:\wxwidgets-x.x.xxx
2、安裝visual c++ express 2008或者安裝mingw32(建議到下載http://tdm-gcc.tdragon.net/,會自動添加環境變數)
3、用VC內建的控制台(不能用系統的,系統控制台因未配置環境變數而出現錯誤“0xc0000135”)進行編譯,編譯兩個版本,unicode的release版和debug版,都使用動態庫(便於跨平台)
編譯命令如下:
1)、進入源碼目錄 cd X:\wxwidgets-x.x.xxx\build\msw
2)、開始編譯
對於vc
nmake -f makefile.vc UNICODE=1 BUILD=release (靜態發行版 預設shared=0)
nmake -f makefile.vc UNICODE=1 BUILD=debug (靜態調試版)
nmake -f makefile.vc SHARED=1 UNICODE=1 BUILD=release (動態發行版)
nmake -f makefile.vc SHARED=1 UNICODE=1 BUILD=debug (動態發行版)
對於mingw32
mingw32-make -f makefile.gcc UNICODE=1 BUILD=release
mingw32-make -f makefile.gcc UNICODE=1 BUILD=debug
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=debug
編譯boost
1、到官網下載最新源碼包和boost-jam-*-ntx86.zip,解壓縮到一臨時檔案夾X:\tmp\boost_1_45_0
2、用VC內建的控制台進行編譯,編譯兩個版本debug和release版
編譯命令如下
1)、進入源碼臨時目錄 cd X:\tmp\boost_1_45_0
2)、查詢需要編譯的模組 bjam --show-libraries
3)、開始編譯,(取消wave,mpi,python三個模組的編譯,而且因為未安裝icu4c,故regex不能支援unicode,其中prefix選項指定boost安裝路徑) 靜態連結庫
bjam install toolset=msvc-9.0 --prefix="c:\boost_1_45_0" debug --without-wave --without-mpi --without-python --without-regex link=static runtime-link=static
bjam install toolset=msvc-9.0 --prefix="c:\boost_1_45_0" release --without-wave --without-mpi --without-python --without-regex link=static runtime-link=static
bjam install toolset=gcc --prefix="c:\boost_1_45_0" debug --without-wave --without-mpi --without-python --without-regex link=static runtime-link=static
bjam install toolset=gcc --prefix="c:\boost_1_45_0" release --without-wave --without-mpi --without-python --without-regex link=static runtime-link=static
動態連結程式庫
bjam install toolset=msvc-9.0 --prefix="c:\boost_1_45_0" debug --without-wave --without-mpi --without-python --without-regex link=shared runtime-link=shared
bjam install toolset=msvc-9.0 --prefix="c:\boost_1_45_0" release --without-wave --without-mpi --without-python --without-regex link=shared runtime-link=shared
bjam install toolset=gcc --prefix="c:\boost_1_45_0" debug --without-wave --without-mpi --without-python --without-regex link=shared runtime-link=shared
bjam install toolset=gcc --prefix="c:\boost_1_45_0" release --without-wave --without-mpi --without-python --without-regex link=shared runtime-link=shared
若是完全編譯則命令如下
bjam install --toolset=msvc-9.0 --prefix="c:\boost_1_45_0" debug --build-type=complete
bjam install --toolset=msvc-9.0 --prefix="c:\boost_1_45_0" release --build-type=complete
添加到codeblocks中去
wxwidgets
當前變數 配置wxwidgets,建立變數wx
添加base路徑 c:\wxwidgets-x.x.xxx
添加include c:\wxwidgets-x.x.xxx\include
添加lib c:\wxwidgets-x.x.xxx\lib
boost
添加base路徑 c:\boost_1_45_0
添加include C:\boost_1_45_0\include\boost-1_45
添加lib C:\boost_1_45_0\lib
對於boost設定全域變數有問題,還是得添加到compiler,linker的尋找路徑中去
設定--》編譯器和調試器設定--》搜尋檔案夾
compiler 添加 c:\boost_1_45_0\include\boost-1_45
linker 添加 C:\boost_1_45_0\lib
使用boost::thread庫時可能會碰到如下錯誤 (linux下 gcc4.4+boost1.40)
||=== testthread, Release ===|
obj/Release/main.o||In function `main':|
main.cpp|| undefined reference to `boost::thread::join()'|
main.cpp|| undefined reference to `boost::thread::join()'|
main.cpp|| undefined reference to `boost::thread::~thread()'|
main.cpp|| undefined reference to `boost::thread::~thread()'|
main.cpp|| undefined reference to `boost::thread::~thread()'|
main.cpp|| undefined reference to `boost::thread::~thread()'|
obj/Release/main.o||In function `boost::detail::thread_data<void (*)()>::~thread_data()':|
::~thread_data()]+0x14)||undefined reference to `boost::detail::thread_data_base::~thread_data_base()'|
obj/Release/main.o||In function `boost::detail::thread_data<void (*)()>::~thread_data()':|
::~thread_data()]+0x11)||undefined reference to `boost::detail::thread_data_base::~thread_data_base()'|
obj/Release/main.o||In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)':|
::type)]+0x4b)||undefined reference to `vtable for boost::detail::thread_data_base'|
::type)]+0x166)||undefined reference to `boost::thread::start_thread()'|
::type)]+0x18a)||undefined reference to `boost::thread_resource_error::thread_resource_error()'|
::type)]+0x192)||undefined reference to `boost::thread_resource_error::~thread_resource_error()'|
::type)]+0x19a)||undefined reference to `typeinfo for boost::thread_resource_error'|
::type)]+0x1ba)||undefined reference to `boost::thread_resource_error::thread_resource_error()'|
::type)]+0x1c2)||undefined reference to `boost::thread_resource_error::~thread_resource_error()'|
::type)]+0x1ca)||undefined reference to `typeinfo for boost::thread_resource_error'|
::type)]+0x1eb)||undefined reference to `boost::thread_resource_error::thread_resource_error()'|
::type)]+0x1f6)||undefined reference to `boost::thread_resource_error::~thread_resource_error()'|
::type)]+0x1fe)||undefined reference to `typeinfo for boost::thread_resource_error'|
::type)]+0x223)||undefined reference to `boost::thread_resource_error::thread_resource_error()'|
::type)]+0x22e)||undefined reference to `boost::thread_resource_error::~thread_resource_error()'|
::type)]+0x236)||undefined reference to `typeinfo for boost::thread_resource_error'|
::type)]+0x25b)||undefined reference to `boost::thread_resource_error::thread_resource_error()'|
::type)]+0x266)||undefined reference to `boost::thread_resource_error::~thread_resource_error()'|
::type)]+0x26e)||undefined reference to `typeinfo for boost::thread_resource_error'|
]+0x8)||undefined reference to `typeinfo for boost::detail::thread_data_base'|
||=== Build finished: 26 errors, 0 warnings (0 minutes, 3 seconds) ===|
或者以下錯誤 (windows gcc4.5+boost1.45)
C:\Boost_1_45\include\boost-1_45\boost\thread\win32\thread_heap_alloc.hpp|59|warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' declared as dllimport: attribute ignored|
C:\Boost_1_45\include\boost-1_45\boost\thread\win32\thread_heap_alloc.hpp|69|warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as dllimport: attribute ignored|
obj\Debug\main.o:main.cpp:(.text$_ZN5boost12thread_groupD1Ev[boost::thread_group::~thread_group()]+0x77)||undefined reference to `_imp___ZN5boost6threadD1Ev'|
obj\Debug\main.o:main.cpp:(.text$_ZN5boost12thread_group8join_allEv[boost::thread_group::join_all()]+0x87)||undefined reference to `_imp___ZN5boost6thread4joinEv'|
::type)]+0x58)||undefined reference to `_imp___ZN5boost6thread12start_threadEv'|
::type)]+0x55)||undefined reference to `_imp___ZN5boost6thread12start_threadEv'|
::~auto_ptr()]+0x14)||undefined reference to `_imp___ZN5boost6threadD1Ev'|
||=== Build finished: 5 errors, 2 warnings (0 minutes, 5 seconds) ===|
以上錯誤是由於未匯入thread的靜態連結庫,解決方案如下
如果使用boost::thread,使用靜態連結時 即編譯boost庫時使用選項link=static runtime-link=static
對於ubuntu下,需要在project的build options中linker settings--》other linker options中添加 -lboost_thread
對於windows下,需要在project的build options中linker settings--》link libraries中添加boost_1_45\lib\libboost_thread-mgw45-mt-1_45.a(注意,debug和release要田間對應的庫檔案),並修改標頭檔(boost_1_45\include\boost_1_45\boost\thread\detail\config.hpp)中第40行,在末尾添加宏 || defined(MINGW32),同時在build options中compiler
settings中的#defines添加MINGW32或者一勞永逸地在全域設定中添加此宏(settings-->compiler and debugger-->compiler settings-->#defines中添加紅MINGW32)
使用動態連結程式庫時,即編譯boost庫時使用選項link=shared runtime-link=shared
對於windows下,需要在project的build options中linker settings--》link libraries中添加boost_1_45\lib\libboost_thread-mgw45-mt-1_45-dll.a(注意,debug和release要田間對應的庫檔案),並將此dll檔案拷貝到編譯的可執行程式根目錄下 |