views:

2381

answers:

3

With VS2005, I want to create a DLL and automatically export all symbols without adding __declspec(dllexport) everywhere and without hand-creating .def files. Is threre a way to do this?

A: 

No, you will need a macro that resolves to double-underscore-declspec(dllexport) when it's included by the .cpp file that implements the exported functions, and resolves to double-underscore-declspec(dllimport) otherwise. (Markdown formatting was having problems with __declspec.)

Adam Mitz
+5  A: 

It can be done...

The way we do it here is to use the /DEF option of the linker to pass a "module definition file" containing a list of our exports. I see form your question that you know about these files. However, we do not do it by hand. The list of exports itself is created by the dumpbin /LINKERMEMBER command, and manipulating the output via a simple script to the format of a module definition file.

It is a lot of work to setup, but it allows us to compile code created without dllexport declarations for Unix on Windows.

Andrew Stein
+1  A: 

I've written a small program to parse the output of "dumpbin /linkermember" on the .lib file. I have upwards of 8,000 function references to export from one DLL.

The problem with doing it on a DLL is that you have to link the DLL without the exported definitions once to create the .lib file, then generate the .def which means you now have to relink the DLL again with the .def file to actually have the references exported.

Working with static libraries is easier. Compile all your sources into static libs, run dumbin, generate a .def with your little program, then link the libs together into a DLL now that the export names are available.

Unfortunately my company won't allow me to show you the source. The work involved is recognizing which "public symbols" in the dump output are not needed in your def file. You have to throw away a lot of those references, NULL_IMPORT_DESCRIPTOR, NULL_THUNK_DATA, __imp*, etc.