Creating a DLL in GCC or Cygwin?

后端 未结 1 2049
耶瑟儿~
耶瑟儿~ 2020-12-06 01:19

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

相关标签:
1条回答
  • 2020-12-06 01:52

    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
    
    0 讨论(0)
提交回复
热议问题