#summary One-sentence summary of this page. = Introduction = STLport working with MinGW = Details = I ,建立mingw环境 最先需要的当然是一个功能完善的mingw环境。这个工作可以通过下载并安装mingw发布的二进制安装包完成。下载地址:http://www.mingw.org http://prdownloads.sf.net/mingw/ 为了清楚理解, 我假设你把msys安装到了C盘C:\ 这样,msys就将在如下位置: c:\msys ---------------------------------------- 2 安装预编译的gcc二进制文件 现在我们已经有了一个基本的工作环境msys了。我们还需要安装gcc的某个版本,以利用它来编译得到最新的gcc版本。下载并安装下列文件。 来自GnuWin32工程: bison: http://prdownloads.sourceforge.net/gnuwin32/bison-2.1-bin.zip?download flex: http://prdownloads.sourceforge.net/gnuwin32/flex-2.5.4a-1-bin.zip?download libiconv: http://prdownloads.sourceforge.net/gnuwin32/libiconv-1.9.2-1-bin.zip?download libintl: http://prdownloads.sourceforge.net/gnuwin32/libintl-0.14.4-bin.zip?download 来自MinGW工程: win32api: http://prdownloads.sourceforge.net/mingw/w32api-3.7.tar.gz?download mingw-runtime: http://prdownloads.sourceforge.net/mingw/mingw-runtime-3.10.tar.gz?download binutils: http://prdownloads.sourceforge.net/mingw/binutils-2.17.50-20060824-1.tar.gz?download gcc-core: http://prdownloads.sourceforge.net/mingw/gcc-core-3.4.5-20060117-1.tar.gz?download 现 在开始安装。先在C盘下创建一个目录gcc, 后面将所有的文件都解压缩到这里。当然你可以下创建其它任何名称的目录。将所有文件都解压缩到gcc目录中。其中libiconv和libintl只需要 解压缩其中的包含了DLL的bin目录就行了,并将bin目录中的内容都复制到gcc/bin目录中。 重要提示:在解压缩完成后,到gcc/bin目录中,删除其中的m4.exe文件(msys使用另一个m4程序,它包含中msys的安装中)。 完成后,将c:\gcc\bin路径加入到系统的PATH路径中去。 注意,我们没有使用gcc-g++包, 这是因为编译gcc不需要C++支持。 这时候,可以测试一下安装是否正常了。打开msys并输入: #gcc -v 这里输出的信息就是预编译gcc的信息。 3,下面开始安装QT Qt软件的下载就不说了,在http://www.trolltech.com/网站上应该可以找到。我这里下载的是qt-win-opensource-4.3.0-mingw.exe这个包(目前最新版),下载完后直接执行安装,在安装过程中提示需要 输入mingw安装目录,需要提示的是要先修改c:\MinGW\include\w32api.h,把__W32API_VERSION改成3.2,__W32API_MINOR_VERSION改成2,不然安装Qt的过程中会报错。 然后把把${MinGW}/bin和${Qt}/bin加到系统路径里 cmd下进入${Qt}/bin,执行qtvars compile_debug,按指示完成配置,然后在同样目录里执行mingw32-make. 需要很长时间(我的破笔记本上超过二个小时。) OK.... 试运行 执行bin目录下的assistant程序,打开Qt的随机文档,进入Qt Reference Documentation->Tutorial & Examples->Qt Tutorial 1 - Hello World!,开始来执行第一个Qt程序。 首先,将examples\tutorial\t1目录下的main.cpp复制到一个新的目录 下,然后从开始菜单中选择"程序"->“Qt by Trolltech v4.3.0 (OpenSource)”->“Qt 4.3.0 Command Prompt”进入到命令行窗口(注:也可以利用cmd来进入到命令行窗口,但通过这个程序进入,会设置好一些环境变量,更加方便。),cd到刚才保存 main.cpp的新目录,按照教程中所说的,执行以下两个命令: qmake -project (这个命令用于产生.pro文件) qmake (这个命令用于产生Makefile文件) 然后执行make指令,成功了, 目前的mingw上并不支持wcout,libstd++不支持,stlport 较早版本也不支持。 现在stlport5.1.3终于让mingw有了宽字符了!所以我要编译stlport 1、下载STLPort5.1.3并解压至C:\STLPort513, 下载网址: http://sourceforge.net/projects/stlport 2启动CMD: 执行cd C:\STLPort510\build\lib, 作为当前目录便于操作; 执行configure -c gcc,配置编译环境,使用 gcc 编译器; 3执行mingw32-make -fgcc.mak clean all,编译STLPort库,这一步比较耗时; 4、安装。 编译成功后, 执行mingw32-make -fgcc.mak install,这一步把编译好的动态库 copy 到 C:\STLPort513\bin目录,连接库 copy 到 C:\STLPort513\lib 目录; 执行mingw32-make -fgcc.mak clobber,清除所有的临时文件。 5、把 C:\STLPort513\lib,C:\STLPort513\stlport 目录加入编译器的搜索路径的最前面,把 C:\STLPort513\bin 加入到系统path中,或者干脆把他们复制到系统文件夹。 6.注意事项: STLport默认的编译目标all是只编译动态版本的 ,如果你只想要动态或者静态版本可以选择性编译。 mingw32-make -fgcc.mak clean 用来清除编译结果。 mingw32-make -fgcc.mak clobber 用来清除临时文件。 写个简单的代码: #include using namespace std; int main() { wcout.imbue(locale("")); wcout << L"你好" << endl; return 0; } 需要注意: 1. 源文件中有中文,我在vi中不能输入中文,所以是用Windows编辑工具写的。 这里有个编码问题,一般不指定就会自动保存为GB2312编码。 gcc将报错:converting to execution character set: Illegal byte sequence 因为gcc是按UTF-8编码读入源文件并输出可执行程序的。 使用 -finput-charset=GB2312 会产生一堆错误: 根源是: In file included from .../stlport/stl/char_traits.h:43, from .../stlport/stl/_iosfwd.h:22, from .../stlport/iostream:38, from main.cpp:2: .../stlport/stl/_construct.h:46:39: failure to convert GB2312 to UTF-8 按理所包含的stlport头文件是纯ASCII,可以当GB2312处理,此处不明! 反正 -finput-charset=GB2312 不能解决问题。 将源文件保存为UTF-8就好了。我用notepad保存,再用UEdit去除头部3 个字节。 另外,在ide中应该这样配置,详细说一下 codeblocks 的设置情况。 1、设置编译器的搜索路径,把你的 STLPort\stlport,STLPort\lib放到搜索路径的最前面。 设置-->编译器和调试器设置: -->Compiler settings-->其它选项:添加"-mthreads",不含引号。 -->Search directories,编译器:添加 STLPort\stlport 到最上面;连接器:添加 STLPort\lib 到最上面。 -->Linker settings, 添加 STLPort\lib 目录下的三个文件。 2、设置编辑器。设置-->编辑器-->常规设置,选择打开夜时的默认编码为:UTF-8。 现在编译、执行上面的代码,It's successful。 如果是命令行,执行 g++ -I%stl%\stlport -mthreads -O2 -c 2.cpp g++ -L%stl%\lib -mthreads -O2 2.o -lstlport.5.1 我这里%stl%是stl目录,2.cpp是实例文件 应该说的很详细了^_^ 过几天再写升级gcc,先把参考资料保存好~~ GCC已经release到4.2.1版本了。用GNU的话说,This release is a major release, containing new features (as well as many other improvements) relative to GCC 4.1.x. 看一下changes,在优化方面,增加了一个option,可以规定参数之间及参数与全局数据间的关系。不过这个option是在语言标准下自动运行的。我水平比较低,没有能理解这个optione 有什么用。 语言方面,OpenMP已经在C,C++,Fortran是被支持了,这下对并发是一个很好我支持吧。 还有两个改进,也是关于option的,是溢出和top-level的,不理解,不管了。 C语言里,有一个比较有用的option,-Waddress,能检测可疑内存地址的使用。不过,有什么具体的效果还不清楚。 C++有一些细节性的改动,如模板的模板参数。还有一个有用的Option,-Wextra,会在 if (a) ; return 1; return 0; 这样的代码里,给一个warnning。对新手可能比较有用,老鸟不大会出现这种错误。 运行库方面,libstdc++添加了对TR1的支持,可以想见,GCC可能是会是最早的对c++0x标准支持的compiler了。 还有-mtune=native和-march=native将会根据cpuid自动选architecture了,方便多了,不用记那么多东西了。 OK,不管怎么样,升级是很不错的,如果你是gcc fans and c++ fans的话. 在linux下,自然不用麻烦了,cygwin我不太习惯用,不伦不类的。mingw32才是win下的正选。不过网上已经有人做了,参考一下: http://www.cublog.cn/u/14337/showart.php?id=196265 我就是照着这个compile的 以下还有几个: http://forum.doom9.org/showthread.php?t=108215 http://leekindo.googlepages.com/gcc-build http://hi.baidu.com/myangelsky/blog/item/997609e980dd903fb90e2d27.html OK,有了以上几个,就一定没有问题了。 不过,如果你像我一样无聊,还喜欢自己乱搞的话,你一定会选自己的目录什么的来编译,如果这样的话,你就要注意了,在configure的时候,一定一定要用相对目录,不然的话…… 我就不幸被这个问题折磨了两个多星期,最后在mingw 的wiki上才找到根结,主要是gengtype这个东东。目前这个bug还没有fix,所以,要小心! 还有,在make的时候,要加上-march和-mtune(或-mcpu),这样会让你compiler和快一点。不过如果你不清楚自己的cpu是什么 march的话(应该不会吧^_!)你可以上gcc.gnu.org上去找,或是编译两次,第二次用上面说的-march=native和-mtune= native Finish! Enjoy! Sorry, in my last message I meant to put gcc.mak instead of gcc-mingw32.mak. I finally decided to just move STLport to its own directory in C:\ because I was getting confused where it was and which copy of the folder I was using. I've now tried three different configurations with MSYS: Attempt 1: cd c:/STLport/build/lib make -f gcc.mak depend make -f gcc.mak install Attempt 2: cd c:/STLport/build/lib configure --compiler gcc make -f gcc.mak clean make -f gcc.mak install Attempt 3: cd c:/STLport/build/lib ./configure make -f gcc.mak depend make -f gcc.mak install In all three cases, everything works fine except when I go on to test it with cd c:/STLport/build/test/unit make -f gcc.mak install In which case I get very bizarre and unreadable errors like I said in the last message. Maybe my problem is that there's some component I don't have installed. Does STLport require anything else besides MinGW and a make program (or in my case MSYS) to get it running? I updated my MinGW installation with the Automated MinGW Installer yesterday before I started any of this. My installed packages: binutils-2.17.50-20060824-1.tar.gz gcc-core-3.4.5-20060117-1.tar.gz gcc-g++-3.4.5-20060117-1.tar.gz mingw-runtime-3.13.tar.gz w32api-3.10.tar.gz At this point, I'm trying to cut out as many unnecessary things as possible, so I've removed Dev-C++ from consideration for the moment by just directly passing the parameters to g++.exe. Using the Windows command line, I've tried both: g++ C:\test.cpp -o test -ID:\STLport\stlport -ID:\MinGW\include -mthreads -LD:\STLport\lib -LD:\MinGW\lib -libstlport.5.1.dll.a And the same thing with an -isystem before each -ID, as suggested in Tim's message where he mentions his wxWindows makefile (I think it was a makefile). I'm using -mthreads because in STLport's INSTALL file it mentions that using STLport means your exe should be multi-threaded, and -mthread and -pthread show unrecognized command errors. Anyway, what happens is that I get this error: C:\MinGW\bin>g++ C:\test.cpp -o test -ID:\STLport\stlport -ID:\MinGW\include -mt hreads -LD:\STLport\lib -LD:\MinGW\lib -libstlport.5.1.dll.a c:\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot fin d -libstlport.5.0.dll.a collect2: ld returned 1 exit status Since I've been trying both STLport 5.0.3 and STLport 5.1.4, I've used libstlport.5.0.dll.a for the former and libstlport.5.1.dll.a for the latter, but neither one works. I've also tried a variety of different commands in place of that final lib reference, including cutting out the "lib" section of the name and replacing it with just "l", and just using -lstlport; g++ displays the same library-not-found message for all of them. The libraries, though, are right there in C:\STLport\lib. I don't know what's wrong. I'm having a lot of trouble finding good information on compiler flags and command line syntax for MinGW, too. Best I could do was this: http://www.cs.chalmers.se/~augustss/hbc/compiling.html. Incidentally, this is my test .cpp: #define UNICODE #include #include int main(int argc, char *argv[]) { std::cout << "Cout."; //std::wcout << "Wcout."; getchar(); return 0; } The whole reason I'm using STLpoint is so I can use wide streams, like wcout. I've commented it out for the time being because STLport isn't linking correctly, so the compiler has no clue what wcout is. -- View this message in context: http://www.nabble.com/Building-STLport-on-MinGW-tf4699301.html#a13448397 Sent from the MinGW - User mailing list archive at Nabble.com. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ MinGW-users mailing list MinGW-users@xxxxxxxxxxxxxxxxxxxxx You may change your MinGW Account Options or unsubscribe at: https://lists.sourceforge.net/lists/listinfo/mingw-users 主环境配置: mingw mingw可以在http://sourceforge.net/projects/mingw上找到,但我 推荐到 http://petra.hos.u-szeged.hu/~aking/www.parinya.ca/或者 http://www.parinya.ca/ 上下载 MinGWStudioFullSetupPlus-2.05.exe 安装到某个分区的根目录,不要安装到"C:\Program Files"之类的目录下.不然后面装msys会很麻烦 这里我安装的是C盘C:\MinGWStudio 然后把C:\MinGWStudio\mingw\bin下的mingw32-make.exe复制一份为make.exe msys: http://sourceforge.net/projects/mingw上找到msys,版本越稳定越好 安装 msys到C:\MinGWStudio\mingGW目录.装完后会谈出dos窗口问你mingw的地址 给它C:/MinGWStudio/MinGW 如果不小心没配好,可以在C:\MinGWStudio\MinGW\sys\etc目录下建立一个fstab文件,加上一行C:/MinGWStudio/mingw /mingw 你以后就可以启动C:\MinGWStudio\MinGW\sys\msys.bat来编译软件了 msys常用命令: cd d: 转到D分区 ls 同dir一样列出目录下的文件 cd /mingw 到mingw目录下.参考前面的配置就会转到C:\MinGWStudio\mingw目录下 cmd 在xp下启动ms的dos shell command 在9x下启动ms的dos shell 库的编译: sdl : 到sdl主站http://www.libsdl.org/index.php下载SDL-devel-1.2.7-mingw32.tar.gz 解压后在MinGWStudio\MinGW\sys目录下建新目录local 启动msys,在sdl目录下打make mingw完成安装. boost 1.32.0编译: http://sourceforge.net/projects/boost下载最新版本 启动msys转到boost目录下 转到tools\build\jam_src目录下: cd /tools/build/jam_src 启动ms的dos shell: 9x下打command命令 xp下打cmd命令 这样进入了dos shell 打入 build.bat mingw 编译完成后jam_src目录下会出现bin.ntx86目录 把bin.ntx86下的文件全部copy到boost目录下. 把/tools/build/v1下的mingw-3_3_1-tools.jam文件copy到boost目录下. 按CTRL+C杀死dos shell.这样又会回到msys的原来的shell.当然你也可以重新启动msys. 在boost目录下敲bjam "-sTOOLS=mingw" install 这会编译你的boost到C盘boost目录下 编译完成后有几百M,还有几十个失败的target那是因为python没配置好.不必理会. 你可以把C:\Boost\include\boost-1_32下的boost目录剪切到 C:\MinGWStudio\Include下(那里还有个古老的wx目录,是MinGWStudio携带的wxwidgets.) 把C:\Boost\lib下的文件剪切到C:\MinGWStudio\Lib下; 然后可以删除C:\BOOST了. 你也可以在mingwstudio中配置boost的include路径指向C:\Boost\include\boost-1_32 lib指向C:\Boost\lib而不必删除C:\boost wxWidgets: http://sourceforge.net/projects/wxwindows下载wxAll后解压缩到一个目录中. 在wxWidgets目录下建一个目录比如mingw什么的. 启动msys,进到wxWidgets目录下刚建立的mingw目录中.打../configure --with-msw --disable-shared 这将建立一个makefile文件.--disable-shared是禁止建立动态连接库.--with-msw不知道意思:) 还是这个目录下敲击make完成库编译. 在这个目录下有sample子目录.你可以进去编译那些例子.运行调试 stlport: 如果你的mingw不是最新版本而是MinGWStudioFullSetupPlus携带的,那么还有希望编译成功stlport. 用msys进入stlport目录的src子目录.打make -f gcc-mingw32.mak 编译成功后会在stlport目录的lib子目录生成库文件. 然后你在mingwstudio中配置头文件指向stlport目录下的stlport目录 库文件指向stlport目录下的lib子目录