在 Eclipse 中使用 MinGW 32 位构建 64 位 dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16955909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Building 64 bit dll with MinGW 32 bit in Eclipse
提问by Marc
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.
我在 Windows 7 64 位上安装了 32 位版本的 Mingw 4.7.2(使用安装程序)。我在 Eclipse C++ 项目中使用 MinGW 来构建一个 .dll 文件。到目前为止一切正常。
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.
但是我使用这个 .dll 通过 JNI 包含在一个 java 项目中。当我在 java 项目中调用 .dll 的函数时,"Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\path\mylib.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform"
抛出异常。所以看起来我需要构建一个 64 位版本的 DLL。
So my questions are:
所以我的问题是:
- Can I build an 64 bit DLL with MinGW 32 bit or do I need the MinGW 64 bit version for that?
- If yes how do I need to adjust the MinGW and/or Eclipse Settings to do so?
- 我可以使用 MinGW 32 位构建 64 位 DLL 还是我需要 MinGW 64 位版本?
- 如果是,我需要如何调整 MinGW 和/或 Eclipse 设置才能这样做?
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.
编辑:正如您在下面的评论中看到的,我已经尝试设置 -m64 标志来构建 64 位 dll。这导致错误:"sorry, unimplemented: 64-bit mode not compiled in"
。那么有没有办法让 64 位模式在 mingw32 中运行?
采纳答案by Gauthier Boaglio
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.
我最近遇到了同样的问题,安装该MinGW-64
版本-m64
为我启用了标志。您可以从这里获得自动构建。
EDIT :Some guy (rubenvb
) made some good job in the Personal Builds
:
编辑:有些人(rubenvb
)在以下方面做得很好Personal Builds
:
回答by Scott Izu
You can download the TDM-GCC compiler with a nice easy Windows installation from http://tdm-gcc.tdragon.net/.
您可以从http://tdm-gcc.tdragon.net/下载带有非常简单的 Windows 安装的 TDM-GCC 编译器。
Then you can run the following to generate a 64-bit C Code Object file from the C Code Source File HelloWorld.c.
然后您可以运行以下命令从 C 代码源文件 HelloWorld.c 生成 64 位 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.
这应该从与 HelloWorld.c 相同的目录中运行,并将在该目录中生成 HelloWorld.o 文件。这-m64
使它成为 64 位。您可以指定-m32
制作 32 位目标文件并指定-o
, 以提供上面评论中提到的输出。
回答by ollo
You can set -m64
switch to compile a 64 bit lib.
您可以设置-m64
switch 来编译 64 位库。
These ‘-m' switches are supported in addition to the above on x86-64 processors in 64-bit environments.
-m32 -m64 -mx32 Generate code for a 32-bit or 64-bit environment. The -m32 option sets int, long, and pointer types to 32 bits, and generates code that runs on any i386 system.
The -m64 option sets int to 32 bits and long and pointer types to 64 bits, and generates code for the x86-64 architecture. For Darwin only the -m64 option also turns off the -fno-pic and -mdynamic-no-pic options.
The -mx32 option sets int, long, and pointer types to 32 bits, and generates code for the x86-64 architecture.
除了上述的 64 位环境中的 x86-64 处理器之外,还支持这些“-m”开关。
-m32 -m64 -mx32 为 32 位或 64 位环境生成代码。-m32 选项将 int、long 和指针类型设置为 32 位,并生成可在任何 i386 系统上运行的代码。
-m64 选项将 int 设置为 32 位,将 long 和指针类型设置为 64 位,并为 x86-64 架构生成代码。对于达尔文,只有 -m64 选项也会关闭 -fno-pic 和 -mdynamic-no-pic 选项。
-mx32 选项将 int、long 和指针类型设置为 32 位,并为 x86-64 架构生成代码。
( source: http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html)
(来源:http: //gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html)
Example:
例子:
32 Bit:gcc -m32 -o exmaple32 example.c
32 位:gcc -m32 -o exmaple32 example.c
64 Bit:gcc -m64 -o exmaple64 example.c
64 位:gcc -m64 -o exmaple64 example.c
(same with g++
)
(同g++
)
You can set them in eclipse: (right click on your project) -> Properties -> C/C++ Build -> Settings
您可以在 eclipse 中设置它们: (right click on your project) -> Properties -> C/C++ Build -> Settings