在 GCC 或 Cygwin 中创建 DLL? [英] Creating a DLL in GCC or Cygwin?

查看:38
本文介绍了在 GCC 或 Cygwin 中创建 DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助将脚本(iterator.c")编译成 DLL.我不能使用 VS2010,因为它支持在 C99 标准中添加到 C 的功能(我使用的是complex.h",但 VB 不支持它).

I need help to compile a script ("iterator.c") into a DLL. I can't use VS2010 since it does not support the features added to C in the C99 standard (I'm using "complex.h" but VB doesn't support it).

我一直在寻找替代品,但我发现的只是 GCC,我不知道如何安装/使用(实际上,我花了半个小时阅读文档,但我没有甚至了解我应该如何安装它)和 Cygwin,我已经安装了它,但我也不知道如何使用.另外,我已经安装了MinGW,但我认为它或多或少与Cygwin相同,我仍然不知道如何制作DLL.

I've been looking for a substitute but all I've found is GCC which I don't know how to install/use (really, I've spent like half an hour reading through the documentation and I don't even understand how am I supposed to install it), and Cygwin, which I've already installed but I don't know how to use either. Also, I've installed MinGW but I think it's the same as Cygwin more or less, and I still don't know how to make a DLL.

并不是我一直很懒惰甚至没有尝试过,只是这些编译器不像我以前用过的任何东西(主要是 Python IDLE 和 Visual Studio,这使事情变得很容易你).我有点迷失了.

It's not like I've been all lazy and haven't even tried it, it's just that these compilers aren't like nothing I've ever used before (mostly Python IDLE and Visual Studio, which make things pretty easy for you). I'm kind of lost.

有人能给我一些关于如何使用这个工具制作一个我可以从另一个脚本访问的 DLL 的建议吗?这真的很重要.

Could someone give me some advice on how to use this tools to make a DLL that I can access from another script? It is really important.

提前致谢.

推荐答案

您必须将 __declspec(dllexport) 放在要导出的方法前面,例如,您可以 #define this 以使其更容易

You must place __declspec(dllexport) in front of the method you wish to export such as, you could #define this to max it easier

EXPORT_DLL void hello() { ... }

编译dll使用

gcc -c -mno-cygwin mydll.c
gcc -shared -o mydll.dll mydll.o -Wl,--out-implib,libmylib.dll.a

然后附加

gcc -o myexe.exe test.o mydll.dll

忘记了最重要的部分,您需要制作一个 mydll.h 文件来包含您的方法定义,以便编译器知道为链接器保留一个位置以便稍后填写.就这么简单

Forgot the most important piece, you need to make a mydll.h file to include your method definition so the compiler knows to reserve a spot for the linker to fill in later on. It's as simple as

#ifndef MYDLL_H
#define MYDLL_H

extern "C" __declspec(dllexport)
#define EXPORT_DLL __declspec(dllexport)

EXPORT_DLL void hello();

#endif

这篇关于在 GCC 或 Cygwin 中创建 DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆