views:

1303

answers:

2

I'm ok with using Cygwin or MinGW, but I need to end up with 64-bit code, not 32-bit. This is because I will be calling the DLL from 64-bit managed C#. I can't seem to find and good references for setting up those tools to create 64-bit binaries. Also, it would be nice if the GCC was version 4, not version 3 as came with my Cygwin install.

An alternative would be some form of interprocess communication. I will research that, but what I laid out above is what I really want.

+3  A: 

The 64-bit MinGW, based on (just released) gcc-4.4.0, is probably your best bet.

Detailed instructions:
1. Download the archive
2. Extract it somewhere under cygwin. In my case, top-level cygwin directory is C:\cygwin, I extracted the package into mingw directory, and ended up with the following contents in C:\cygwin\mingw (which is visible as /mingw under 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

3. Now compile some C++ code. I used:

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

using namespace std;
int main()
{
    vector<string> vs;
    vs.push_back("abc");
}

And compile it like this:

$ /mingw/bin/x86_64-pc-mingw32-g++ t.cc

4. Finally, verify the result is a Windows/x 64 executable, by running dumpbin /headers a.exe:

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
Employed Russian
Those are Linux packages, right? I would like to build and run on Windows.
Fantius
Ahh, I just noticed a Windows build under the Automated Builds folder at the link you posted. I think that will be exactly what I need.
Fantius
I'm having trouble making this work. When I previously installed MinGW32, I used an installer. This is not an installer. I have added the bin folder to my path and it can find g++, but g++ has no idea where to look for the headers and libraries. When I used the installer, everything just worked.
Fantius
It worked! Initially I got the same error that I did when using the 64-bit prebuild drangon.com toolchain (cc1plus.exe crash) (see my comment in my question), so then I created a clean XP VM and did it there. Bottom line, it finally worked. Thank you!
Fantius
A: 

The gcc docs say:

These `-m' switches are supported in addition to the above on AMD x86-64 processors in 64-bit environments.

-m32 -m64 Generate code for a 32-bit or 64-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system. The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture.

Note that that's going to drive you crazy, I think, if mingw really does it that way, since normally on Windows 64 long is 32 bits and long long is the 64-bit pointer-sized type.

Mike G.
I tried that in Cygwin and MinGW and they both complained that 64-bit mode is not compiled in. That's pretty much what I expected to happen because I don't have the 64-bit version of either of those things. That's what I'm trying to find.
Fantius
The mingw gcc configured with --target=x86_64-pc-mingw32 produces code with sizeof(long) == 4 and sizeof(long long) == 8
Employed Russian