Advertisement

compiling a dll in linux

Started by October 04, 2003 02:08 PM
2 comments, last by browny 21 years, 4 months ago
Well.. i am just looking for how to compile a dll (*.so) in linux from ground up. Since i have been programming in windows platform for quite a long time..so i am basically looking for __declspec(dllexport) using a DEF file and how to create a EXPORT library along with a *.dll ( *.so in linux) using GCC compiler
Z
Shared objects in *nix work differently from DLLs in Windows. You will not have to explicitly export functions or import functions (it can be linked like any other object file and even built much the same way). For more information, see this tutorial.

Advertisement
.so libraries on Unix typically follow the C/C++ conventions for exporting. I.e. the "extern" keyword is all that is necessary.

To export a function, just do:

extern void MyFunction();

A typicaly cross platform approach is to do something like this:

#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

extern void DLLEXPORT MyFunction(void);

Remember to add "C" (i.e. extern "C" void DLLEXPORT MyFunction) to the line if you want to do explicit linking (LoadLibrary/dlopen, GetProcAddress/dlsym), as C++ name mangling will make it impossible to look up something by name.
quote:
Original post by Anonymous Poster
.so libraries on Unix typically follow the C/C++ conventions for exporting. I.e. the "extern" keyword is all that is necessary.

To export a function, just do:

extern void MyFunction();

A typicaly cross platform approach is to do something like this:

#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

extern void DLLEXPORT MyFunction(void);

Remember to add "C" (i.e. extern "C" void DLLEXPORT MyFunction) to the line if you want to do explicit linking (LoadLibrary/dlopen, GetProcAddress/dlsym), as C++ name mangling will make it impossible to look up something by name.



You don''t even need the extern
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon

This topic is closed to new replies.

Advertisement