Home > Uncategorized > Exporting symbols from a DLL

Exporting symbols from a DLL

Still playing with Visual Studio C++ 2005…

When I build a JNI DLL I get an import library (.lib). As DLL are dynamically binded to the JVM I do not need this file. Now let’s concider building a DLL from something which used to be a static library (and to be a bit more realistic a Linux static library). In this case the .lib is not created.

By default Visual Studio do not export symbols in DLL and GCC have the oposit behavior. There is no problems with JNI libraries because javah and jni.h handle the definition of exports. So how to define such exports ?

It can be done with __declspec(dllimport) and __declspec(export) keywords. If you are compiling the DLL you must use __declspec(export). If you are linking an application to your DLL you must define the symbol with __declspec(dllimport). As you are using the same header file to define exports and imports you will have to play with #define.

Recent GCC versions also have this feature. It allow to dramatically reduce the size and the load time of libraries. Read this page to know more. There are also examples on how to use __declspec(dllimport) and __declspec(dllexport) in a common header

Here is the MSDN reference concerning DLL import/exports

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: