ld and export lists

Nick Clifton nickc@redhat.com
Mon Jan 13 16:47:00 GMT 2003

Hi Robert,

> How does one define an export list for a shared library using
> ld.

By using a DEF file.

Have a look at the information in the ld.texinfo file for more details
about this.  (You should get a copy of the latest version from the CVS
repository, since this section has seen a lot of work in the last few
months).  In particular in the WIN32 section of the Machine Dependent
Features section it says this:

  _exporting DLL symbols_
     The cygwin/mingw `ld' has several ways to export symbols for dll's.

    _using auto-export functionality_
          By default `ld' exports symbols with the auto-export
          functionality, which is controlled by the following command
          line options:

               --export-all-symbols   [This is the default]

    _using a DEF file_
          Another way of exporting symbols is using a DEF file.  A DEF
          file is an ASCII file containing definitions of symbols which
          should be exported when a dll is created.  Usually it is
          named `<dll name>.def' and is added as any other object file
          to the linker's command line.

               gcc -o <output> <objectfiles> <dll name>.def

          Here is an example of a DEF file for a shared library called

               LIBRARY "xyz.dll" BASE=0x10000000
               _bar = bar

          This example defines a base address and three symbols.  The
          third symbol is an alias for the second.  For the complete
          format specification see ld/deffilep.y in the binutils

          While linking a shared dll, `ld' is able to create a DEF file
          with the `--output-def <file>' command line option.


More information about the Binutils mailing list