Export Symbols from a DLL

When you build a DLL, exporting symbols means making the names of data items, functions, and classes visible outside your DLL. Export symbols to make them accessible by modules that use your DLL.

There are two ways to export symbols:

  1. Modify your source code to explicitly export symbols
  2. Use link options in your configuration file to export symbols

You can combine both methods. All symbols exported by the source code and all symbols exported by link options are exported during the build process.

Modify Your Source Code
Apply one of the following constructs to every symbol you want to export:

Declaring a class with _Export exports the virtual function table as well as static data members of the class. You should do this if the class has constructors or destructors that are inline or are defined by the compiler. Here is a sample declaration:

class _Export camera {
   virtual void focus();
};

Exporting symbols from source requires no further action during the build.

Use Link Options
If you do not want to include the constructs listed above in your source, you can export symbols at link time. You can use one of the following link options:

These options are cumulative. For example if you specify link(export_NameSpace, jon) and link(export_Prefix, RK_), all symbols in namespace jon and all symbols that begin with the letters RK_ are exported. Similarly, you can export some symbols by naming them individually with link(export, name) and others symbols by listing them in the file named with link(exportfile, fileName).

If you want to individually name selected symbols to export from the DLL, you must use link(exportList, fileName) or link(export, ...). Using these two options gives you greater flexibility than exporting symbols from the source. For example you can export a function with a different name from its name inside the DLL. However, these two options have the following complications:

The link options exportAll, export_NameSpace, and export_Prefix are easier to use than export or exportAll because you do not have to specify mangled and decorated names.

An advantage of link(exportAll), link(export_NameSpace, name), and Link(export_Prefix) is that they automatically exports virtual function tables. This is helpful if you have classes that are implemented in the DLL and use constructors or destructors that are supplied by the compiler or that may be inlined in target modules not built from the same configuration files as the DLL. If the virtual function table is not visible, the linker cannot satisfy references when modules use the DLL to access the virtual function table of the class.

A disadvantage of link(exportAll) is that the target executable may be larger than if you export only selected symbols, because the name of each exported symbol appears in the export string table of the executable. The DLL may take longer to load because the loader must search a larger export table in order to satisfy the import requirements.



Configuration Files
Decorated and Mangled Names


Build Dynamic Link Libraries
Build Modules That Use DLLs
Get Mangled Names for C++ Symbols
Convert Module Definition Files


Link Options