在 GCC 或 Cygwin 中创建 DLL?

发布于 2024-11-24 00:40:59 字数 436 浏览 5 评论 0原文

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

我一直在寻找替代品,但我发现的是 GCC,我不知道如何安装/使用(真的,我花了半个小时阅读文档,我什至不明白如何安装/使用)我应该安装它吗?)和 Cygwin,我已经安装了它,但我不知道如何使用。另外,我已经安装了MinGW,但我认为它与Cygwin或多或少相同,而且我仍然不知道如何制作DLL。

这并不是说我太懒了,甚至没有尝试过,只是这些编译器与我以前使用过的任何编译器都不一样(主要是 Python IDLE 和 Visual Studio,这让你的事情变得非常简单)。我有点迷失了。

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

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).

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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2024-12-01 00:40:59

您必须将 __declspec(dllexport) 放在您希望导出的方法前面,例如,您可以#define this to max it更容易

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 文件包含您的方法定义,以便编译器知道为链接器保留一个位置以便稍后填充。就这么简单

#ifndef MYDLL_H
#define MYDLL_H

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

EXPORT_DLL void hello();

#endif

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() { ... }

To compile the dll use

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

then to attach

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

EDIT: 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文