如何编译64位Windows的现有posix代码?

Fan*_*ius 6 64-bit cygwin win64 mingw

我没有使用Cygwin或MinGW,但我需要最终得到64位代码,而不是32位代码.这是因为我将从64位托管C#调用DLL.我似乎无法找到设置这些工具来创建64位二进制文​​件的好参考.如果GCC是版本4,而不是我的Cygwin安装版本3,那将是很好的.

另一种方法是进行某种形式的进程间通信.我会研究这个,但我上面列出的是我真正想要的.

Emp*_*ian 6

基于(刚刚发布)gcc-4.4.0 的64位MinGW可能是你最好的选择.(由于sourceforge.net上的mingw-w64项目正在转向mingw-w64.org,最好使用mingw-w64.org)

详细说明:
1.下载存档
2.在cygwin下的某处解压缩.在我的情况下,顶级cygwin目录是C:\cygwin,我将包解压缩到mingw目录中,最后得到以下内容C:\cygwin\mingw(/mingw在cygwin下可见:

$ ls -l /mingw
total 1
drwxr-xr-x+ 2 user None  0 May 10 08:32 bin
drwxr-xr-x+ 2 user None  0 May 10 05:45 include
drwxr-xr-x+ 2 user None  0 May 10 08:30 info
drwxr-xr-x+ 3 user None  0 May 10 08:30 lib
drwxr-xr-x+ 3 user None  0 May 10 05:45 libexec
drwxr-xr-x+ 4 user None  0 May 10 05:45 man
lrwxrwxrwx  1 user None 17 May 17 17:20 mingw -> x86_64-pc-mingw32
drwxr-xr-x+ 3 user None  0 May 10 04:16 share
drwxr-xr-x+ 5 user None  0 May 10 04:18 x86_64-pc-mingw32
Run Code Online (Sandbox Code Playgroud)

3.现在编译一些C++代码.我用了:

// t.cc
#include <vector>
#include <string>

using namespace std;
int main()
{
    vector<string> vs;
    vs.push_back("abc");
}
Run Code Online (Sandbox Code Playgroud)

并像这样编译它:

$ /mingw/bin/x86_64-pc-mingw32-g++ t.cc
Run Code Online (Sandbox Code Playgroud)

4.最后,通过运行dumpbin /headers a.exe以下命令验证结果是Windows/x 64可执行文件:

Microsoft (R) COFF/PE Dumper Version 7.00.9466
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file a.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
            8664 machine (AMD64)
              10 number of sections
        4A10AF9F time date stamp Sun May 17 17:45:19 2009
           ABA00 file pointer to symbol table
             EC4 number of symbols
              F0 size of optional header
              27 characteristics
                   Relocations stripped
                   Executable
                   Line numbers stripped
                   Application can handle large (>2GB) addresses
Run Code Online (Sandbox Code Playgroud)