Thursday 15 August 2013

c++ - Creating shared and static libraries using g++ (under Windows) -


How do I create a static and dynamic library for Windows using G ++?

I have received some commands for Linux to create the .so files, and I have tried to apply them to the Windows shell, but they have .dll < / Code> Files that fail to link to my application runtime

I have been able to create .dll files using only visible code ++, but I can command them I want to manually create a line, preferably g ++ . I would also like to know how to prepare static libraries for Windows

The prefix is ​​required:

  __ declspec (dllexport) ...   

the features you want to show.

See.

Example for C Function:

  __Decspeak (dlxport) Add int __cdecl (int a, int b) {return (a + b); }   

This can be simplified using macros : everything is explained on this.


For C ++ classes, you do not need to apply only each class (not every single method)

I usually do this:

Note: also ensures portability ...

Include file:

 For the export of version     

Usage:

  #include "my_macros.h" class LIB_CLASS MyClass { }   

Then, for build , simply:

  • pass the option -DBUILD_LIB Optional Compiler Command Line
  • Pass the -shared option for the General Linker Command Line option

No comments:

Post a Comment