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文件拷贝到编译的可执行程序根目录下
编译环境
操作系统:SUSE linux Enterprise Server 10 64-bit
编译工具:gcc 4.1.2
1.下载boost1.36
2.解压boost到/usr/share
3.在命令行运行/usr/share/boost_1_36_0/tools/jam/src/build.sh生成bjam
4.复制/usr/share/boost_1_36_0/tools/jam/src/bin.linuxx86_64/bjam到/usr/bin目录下
5.配置/usr/share/boost_1_36_0/tools/build/v2/user-config.jam中使用的编译工具
using gcc ;
6.使用bjam --build-type=complete --with-XXXX stage 编译指定库或者使用
bjam --build-type=complete stage 完全编译boost库,库文件编译完成后存放在
/usr/share/boost_1_36_0/stage/lib目录下.由于大部分boost库并不需要编译可直接使用,
通常我们可选择性的编译需要的库.
7.如需要使用bjam编译应用程序,编辑/etc/profile,在文件最后增加
export BOOST_ROOT = /usr/share/boost_1_36_0
export BOOST_INCLUDE = /usr/share/boost_1_36_0
export BOOST_LIB = /usr/share/boost_1_36_0/stage/lib
8.为了让编译工具能搜索到boost库的头文件和库文件,我们使用ln命令建立连接
8.1创建头文件连接
ln -s /usr/share/boost_1_36_0/boost /usr/include/boost
8.2创建库文件连接,为了方便我们可使用jam帮助我们完整这项工作,在
/usr/share/boost_1_36_0/stage/lib下创建Jamroot
# Jamroot脚本 local files = [ glob * . * ] ; local curpath ; local install_lib_files = [ glob / usr / lib /* . * ] ; local cmd ; local source_path ; local desc_path ; path - constant curpath : . / ; for local file in $ (files) { source_path = $ (curpath) /$ (file) ; desc_path = " /usr/lib/ " $ (file) ; cmd = " ln -s " $ (source_path) " " $ (desc_path) ; if $ (desc_path) in $ (install_lib_files) { ECHO $ (desc_path) " is exists " ; } else { ECHO $ (cmd) ; SHELL $ (cmd) ; } }
以上脚本将/usr/share/boost_1_36_0/stage/lib目录下的所有库文件创建连接符号到
/usr/lib目录下.
9.编译完成