2008年1月6日星期日

mingw+code:blocks+wxwidget


最近C++开发想抛弃微软,投向开源,经过多方搜索,选择了mingw+code:blocks+wxwidget。


安装编译指南:


参考:
http://blog.csdn.net/aspen_yang/archive/2007/12/06/1920783.aspx


1,安装MinGW
官方网站上下载自动安装的版本,它会边下载边安装,安装时注意选上G++和make,安装完后设置好环境变量C:\MinGW\bin


2,安装Code:Blocks
下载推荐的每天build版本,即需要的mingw和wxWidgets的dll,解压到一个目录即可,不用安装。
打开主程序,设置编译器为GNU GCC COMPILER,在settings->complier debuger setting 里面设置编译器的路径。

3,编译opencv
INSTALL里有编译说明
测试OPENCV,加入库和头文件的路径等,编译连接通过,但是不能执行,出错
怀疑是必须要用mingw重新编译openCV,故编译出错:

E:\program\OpenCV\_make>mingw32-make -f make_all_gnu.mak
mingw32-make: *** ../_temp/cxcore_Rls: No such file or directory. Stop.
mingw32-make: *** [all] Error 2

郁闷阿,编译OPENCV太麻烦了!编译的步骤install文件里有讲解,但是makefile里的mkdir命令老是出错,
最后只能是手工建立的目录。编译highgui时又出错,按照install文件里说的:
mingw32-make -f make_all_gnu.mak - build IA32 version with gcc compiler
(Make sure that <gcc_root>\bin is in the system path.
To build VFW-enabled highgui, read instructions in
opencv\otherlibs\_graphics\readme.txt)
按照这个文件里说的,复制vc6.0里的相关头文件,覆盖掉mingw的(之前最好备份),之后编译可以了。

是编译debug的还是release的,可以在mak文件里设置。

要注意编译前备份好bin目录下的文件和lib目录下的lib文件,以免被覆盖掉。



3,编译wxWidgets
install.txt里面有安装说明

../configure --with-msw --enable-release --enable-monolithic --disable-shared --enable-odbc
配置。


NOTE: The makefile.gcc makefiles are for compilation under MinGW using
Windows command interpreter (command.com/cmd.exe), they won't work in
other environments (such as UNIX or Unix-like, e.g. MSYS where you have
to use configure instead, see the section below)

make -f makefile.gcc BUILD=debug
用这个会出错,可能是因为环境里面已经有了mkdir等命令,不能使用cmd自带的了。

opencv的make_all_gnu.mak和wxWidgets的makefile.gcc都是利用cmd.exe的。



开始从网上看到,opencv不用再编译就可以,但是实验着不行,编译连接都没有事,就是执行的时候程序崩溃,提示内存访问越界。这里有mingw与vc的dll之间相互调用的解答:http://wyw.dcweb.cn/dllfaq.htm,但还不是很具体,google,baidu了一天多,有可能是以下情况:


1,Now for MinGW programs calling an MSVC DLL. We have two methods.
One way is to specify the LIB files directly on the command line after the main program (in newer MinGW versions;
MinGW GCC 2.95.2 is reported not to work). For example, after


cl /LD testdll.c


use


gcc -o testmain testmain.c testdll.lib


高版本的不支持?


2,对于静态库,如d3dx.lib在pre-April 2005 SDK,我们就没有必要使用reimp。只是在编译链接的链接阶段,把它作为object文件加以链接。如:


G++ test.cpp d3dx.lib o test.exe


静态库可以,动态库不可以这样用?


3,> I tried linking something by putting ftd2xx.lib directly on the command line
> and it appeared to work (no errors) but examining the import table shows
> that something is wrong and that it would cause an application to crash.
There is a bug in latest binutils RC that does the wrong thing with MSVC import
libs. The bug was not in older binutils and it is fixed in CVS.


http://marc.info/?l=mingw-users&m=107687856431472&w=2


这是一个bug???


晕死!估计是bug的可能性比较大,因为编译链接没有问题,说明在引入库中找到了函数入口。执行的时候没有提示"找不到函数入口",说明在dll中也找到了函数入口,内存访问越界,应该是参数的传入,释放等有问题!


使用第二种方法是可以的。



没有评论: