用mingw编译程序时报错:
0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487 AllocationBase 0x0, BaseAddress 0x71690000, RegionSize 0x410000, State 0x10000 C:\MSYS-TEMP\bin\sh.exe: *** Couldn't reserve space for cygwin's heap, Win32 error 6
原因是用到的msys-1.0.dll基地址冲突,需要rebase。虽然在win7下mingw编译c++程序也可以用windows命令来操作文件,但是因为项目中有几个qt工程,自动生成的makefile需要msys来模拟linux环境操作文件。所以msys还是不能绕过。
解决方案:在命令行窗体键入:rebase -b 0x30000000 path/msys/1.0/bin/msys-1.0.dll
上述用到的rebase工具在visual studio和cygwin中都有,任选一个安装即可。上述path是msys所在的路径。
根据http://support.code-red-tech.com/CodeRedWiki/VirtualAllocPointerNull中的描述,上述操作若解决问题,则并不保证问题不会重现,这依赖于系统中同时运行的其它程序。若再出现则需要再次rebase到其它地址。
根据http://cygwin.wikia.com/wiki/Rebaseall中的描述,此问题在64位的cygwin中应该不存在。
上述问题并不会影响最终编译生成的目标程序,因为msys-1.0.dll只是makefile用来操作文件,并没有作为动态库链接到目标程序中。