2023年11月29日发(作者:)

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

windows下编译wxwidgetsboost并加入到codeblocks路径中

(visual c++ 2008/mingw32)

编译wxwidgets

1、到官网下载源码包(MSW),安装到 X:

2、安装visual c++ express 2008或者安装mingw32(建议到下

/,会自动添加环境变量)

3、用VC自带的控制台(不能用系统的,系统控制台因未配置环境变

量而出现错误“0xc0000135”)进行编译,编译两个版本,unicode

release版和debug版,都使用动态库(便于跨平台)

编译命令如下:

1)、进入源码目录 cd X:ldmsw

2)、开始编译

对于vc

nmake -f UNICODE=1 BUILD=release (静态发行版

默认shared=0)

nmake -f UNICODE=1 BUILD=debug (静态调试

)

nmake -f SHARED=1 UNICODE=1 BUILD=release

(动态发行版)

nmake -f SHARED=1 UNICODE=1

BUILD=debug (动态发行版)

对于mingw32

mingw32-make -f UNICODE=1 BUILD=release

mingw32-make -f UNICODE=1 BUILD=debug

mingw32-make -f SHARED=1 UNICODE=1

BUILD=release

mingw32-make -f SHARED=1 UNICODE=1

BUILD=debug

编译boost

1到官网下载最新源码包和boost-jam-*-解压缩到一临

时文件夹X:tmpboost_1_45_0

2、用VC自带的控制台进行编译,编译两个版本debugrelease

编译命令如下

1)、进入源码临时目录 cd X:tmpboost_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

若是完全编译则命令如下

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:

添加include c:lude

添加lib c:

boost

添加base路径 c:boost_1_45_0

添加include C:boost_1_45_0includeboost-1_45

添加lib C:boost_1_45_0lib

对于boost设置全局变量有问题,还是得添加到compilerlinker

寻找路径中去

设置--》编译器和调试器设置--》搜寻文件夹

compiler 添加 c:boost_1_45_0includeboost-1_45

linker 添加 C:boost_1_45_0lib

使用boost::thread库时可能会碰到如下错误(linux

gcc4.4+boost1.40

||=== testthread, Release ===|

obj/In function `main':|

|| undefined reference to `boost::thread::join()'|

|| undefined reference to `boost::thread::join()'|

|| undefined reference to

`boost::thread::~thread()'|

obj/In function

`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

C:Boost_1_45includeboost-1_45boostthreadwin32thre

ad_heap_|59|warning: inline function 'void*

boost::detail::allocate_raw_heap_memory(unsigned int)'

以上错误是由于未导入thread的静态链接库,解决方法如下

如果使用boost::thread,使用静态链接时即编译boost库时使用选项

link=static runtime-link=static

对于ubuntu下,需要在projectbuild optionslinker settings--

other linker options中添加 -lboost_thread

对于windows下,需要在projectbuild optionslinker

settings--link libraries中添加

boost_1_45liblibboost_thread-mgw45-mt-1_45.a(注意,

debugrelease要田间对应的库文件),并修改头文件

boost_1_45includeboost_1_45boostthreaddetailconfi

)中第40行,在末尾添加宏 || defined(MINGW32),同时在

build optionscompiler settings中的#defines添加MINGW32

或者一劳永逸地在全局设定中添加此宏(settings-->compiler and

debugger-->compiler settings-->#defines中添加红MINGW32

使用动态链接库时,即编译boost库时使用选项link=shared

runtime-link=shared

对于windows下,需要在projectbuild optionslinker

settings--link libraries中添加

boost_1_45liblibboost_thread-mgw45-mt-1_45-dll.a(注意,

debugrelease要田间对应的库文件),并将此dll文件拷贝到编译的

可执行程序根目录下