Creating a DLL in GCC or Cygwin?

I need help compiling a script ("iterator.c") into a DLL. I can’t use VS2010, because it doesn’t support the functions added to C in the C99 standard (I use "complex.h", but VB does not support it).

I was looking for a replacement, but all I found is GCC, which I don’t know how to install / use (indeed, I spent half an hour reading the documentation, and I don’t even understand how I should install it) and Cygwin, which I already installed, but I do not know how to use it. In addition, I installed MinGW, but I think it looks like Cygwin more or less, and I still don't know how to make a DLL.

It doesn't seem like I was lazy or even tried it, it's just that these compilers are not like anything I have ever used before (mostly Python IDLE and Visual Studio, which makes things pretty easy for you) . I am lost.

Can someone give me some tips on how to use these tools to create a DLL with which I can access from another script? This is really important.

Thanks in advance.

+8
c gcc compiler-construction c99 dll
source share
1 answer

You should put __declspec (dllexport) in front of the method you want to export, for example, you can #define this to make it easier

EXPORT_DLL void hello() { ... } 

To compile dll use

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

then attach

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

EDIT: Forgot the most important piece, you need to make the mydll.h file to include the definition of your method so that the compiler knows to reserve space for the linker to fill in later. It is as simple as

 #ifndef MYDLL_H #define MYDLL_H extern "C" __declspec(dllexport) #define EXPORT_DLL __declspec(dllexport) EXPORT_DLL void hello(); #endif 
+11
source share

All Articles