codeblocks + wxwidgets + boost 搭建 c++ 开发平台步骤

原网址:http://hi.baidu.com/bpboy/item/0e17fdf44c5e1248932af28c

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文件拷贝到编译的可执行程序根目录下

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值