Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building 64 bit dll with MinGW 32 bit in Eclipse

I installed the 32 bit version of Mingw 4.7.2 (using the installer) on my Windows 7 64 bit. I use MinGW in an Eclipse C++ project in order to build a .dll file. So far everything works.

However I use this .dll to be included in a java project via JNI. And when I call a function of the .dll in the java project the exception "Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\path\mylib.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform" is thrown. So it seem like I need to build an 64 bit version of the DLL.

So my questions are:

  1. Can I build an 64 bit DLL with MinGW 32 bit or do I need the MinGW 64 bit version for that?
  2. If yes how do I need to adjust the MinGW and/or Eclipse Settings to do so?

Regards Marc

Edit: As you can see in the comment below, I already tried to set the -m64 Flag to build a 64 bit dll. This results in the error: "sorry, unimplemented: 64-bit mode not compiled in". So is there a way to get the 64 bit mode running in mingw32.

like image 739
Marc Avatar asked Jun 06 '13 07:06

Marc


People also ask

Can a 32-bit program load a 64-bit DLL?

Additionally, a 32-bit process cannot load a 64-bit DLL. However, 64-bit Windows supports remote procedure calls (RPC) between 64-bit and 32-bit processes (both on the same computer and across computers).

Does Mingw 32 work on 64-bit?

MinGW can be run either on the native Microsoft Windows platform, cross-hosted on Linux (or other Unix), or "cross-native" on Cygwin. Although programs produced under MinGW are 32-bit executables, they can be used both in 32 and 64-bit versions of Windows.

How do you call a 64-bit DLL from a 32-bit application?

Solution. You cannot call a 64-bit DLL from 32-bit LabVIEW. This is a limitation of 64-bit Windows, which does not support mixed 64-bit/32-bit processes. The recommended solution is to recompile the DLL from the source code for a 32-bit target architecture.

How do I change my Mingw from 32-bit to 64-bit?

open a cmd.exe and do set PATH=C:\mingw64\bin;%PATH% for 64-bit building. set PATH=C:\mingw32\bin;%PATH% for 32-bit building. You should be ready to go.


2 Answers

I recently faced the same problem, installing the MinGW-64 version enabled the -m64 flag for me. You can get an automated build from here.

EDIT : Some guy (rubenvb) made some good job in the Personal Builds :

There's gcc 4.7.4 here and even 4.8.0 here.

like image 81
Gauthier Boaglio Avatar answered Oct 07 '22 21:10

Gauthier Boaglio


You can download the TDM-GCC compiler with a nice easy Windows installation from http://tdm-gcc.tdragon.net/.

Then you can run the following to generate a 64-bit C Code Object file from the C Code Source File HelloWorld.c.

"C:\MinGW64\bin\gcc.exe" -m64 -c -I"C:\Program Files\Java\jdk1.6.0_26\include" -I"C:\Program Files\Java\jdk1.6.0_26\include\win32" HelloWorld.c 

This should be run from the same directory as HelloWorld.c and will generate the HelloWorld.o file in that directory. The -m64 makes it 64 bit. You can specify -m32 to make a 32 bit object file and specify -o, to give the output as mentioned in the comment above.

like image 20
Scott Izu Avatar answered Oct 07 '22 22:10

Scott Izu