Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export function from DLL in Visual Studio 2010 using DEF

I inherited a huge C++ multi-project solution with many dynamic libraries but without any

__declspec(dllexport)

I learned that one does not necessarily have to insert any dllexport (would be much work) but that one can use a .def file in addition to corresponding .dll instead.

In order to try that I built a "DLL Hello World" project from here, removed the dllexport from the header and...failed desperately. In the words of already cited page, my key question is how to

"[..] use the .def file when building the DLL."

My .def file is (I try the code only with the Add method):

LIBRARY   MathFuncsDll
EXPORTS 
?Add@MyMathFuncs@MathFuncs@@SANNN@Z

How do I use it when building the DLL in Visual Studio 2010 in order to export the Add method?

like image 719
Finnfalter Avatar asked Jan 18 '13 15:01

Finnfalter


1 Answers

After having passed half a day in front of this problem, I just found the solution: it is described here.

To resume the process of symbol export with .def files in VS2010 using my own words:

  1. Tell VS2010 to compile a dynamic library (.dll). This is done in the Property Page of the library's project.
  2. Craft a module definition file (.def) by using mangled (decorated) names (at least when Your language is C++). If You make use of dllexport You can display already exported symbols of Your .dll as described here. If You haven't anything exported yet, see this post.
  3. Add the .def to the library definition in its Property Page.
  4. Compile
  5. Verify the correctness of Your work, for example with Dependency Walker by opening the dependent file, e.g. .exe. You should see the just compiled library in a dependency tree below the dependent file. There should be no errors or warnings, e.g. no red colour.

If You have further questions concerning .def files, look out for the terminus "Module definition file".

like image 103
Finnfalter Avatar answered Oct 20 '22 17:10

Finnfalter