在创建或GCC Cygwin的一个DLL? [英] Creating a DLL in GCC or Cygwin?

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

问题描述

我需要帮助编译脚本(iterator.c)到一个DLL。因为它的不可以支持C99标准添加到C的功能,我不能使用VS2010(我使用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,这使事情$ P $用过ptty您轻松)。我有点失去了。

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)的在前面的方法你想如出口,你可以#定义这最大值更容易

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天全站免登陆