DrDonut
DrDonut

Reputation: 904

DLL functions not exported when build in release configuration

In my C++ DLL project, when I build the project in Debug configuration, it works perfectly.

Functions are exported using a .def file:

LIBRARY "calc"
EXPORTS
findMaxFreqEXL = findMaxFreq
findMinSpeedEXL = calcMinSpeed
findMaxSpeedEXL = calcMaxSpeed
createProfileEXL = createProfile
arrayTestEXL = arrayTest
setLimitsEXL = setLimits

And those functions are all defined in my project as:

double _stdcall findMaxFreq(double &dCutLength, double &dCutTime, double &dSealTime, double &dCutSpeed, double &dDoughHeight, double* limitArray)
{
Calc *calcObj = new Calc();
calcObj->setLimits((int)limitArray[0], (int)limitArray[1], (int)limitArray[2], (int)limitArray[3], limitArray[4], limitArray[5], (int)limitArray[6], (int)limitArray[7], (int)limitArray[8], (int)limitArray[9], (int)limitArray[10]);
double maxFreq = calcObj->calcMaxFreq((float) dCutLength, (float) dCutTime, (float) dSealTime, (float) dCutSpeed, (float) dDoughHeight);

//delete calcObj;
return maxFreq;
}

And so on for the rest of the functions.

The generated DLL file is 192 kb in size, and according to dumpbin, these are the exported functions:

Dump of file C:\Redacted\Debug\calcDLL.dll

File Type: DLL

Section contains the following exports for calc.dll

00000000 characteristics
57B17EE6 time date stamp Mon Aug 15 10:35:50 2016
    0.00 version
       1 ordinal base
       6 number of functions
       6 number of names

ordinal hint RVA      name

      1    0 00013339 arrayTestEXL = @ILT+820(?arrayTest@@YGHPAN@Z)
      2    1 00013460 createProfileEXL = @ILT+1115(?createProfile@@YGHAAN00000PAN11@Z)
      3    2 000138E8 findMaxFreqEXL = @ILT+2275(?findMaxFreq@@YGNAAN0000PAN@Z)
      4    3 00013744 findMaxSpeedEXL = @ILT+1855(?calcMaxSpeed@@YGNAAN00@Z)

      5    4 00013500 findMinSpeedEXL = @ILT+1275(?calcMinSpeed@@YGNAAN00@Z)

      6    5 000134F6 setLimitsEXL = @ILT+1265(?setLimits@Calc@@QAEXHHHHHHHHHHH@Z)

Summary

    1000 .data
    2000 .idata
    5000 .rdata
    2000 .reloc
    1000 .rsrc
   28000 .text
   12000 .textbss

In Release configuration the file is only 10 kb and dumpbin says this:

Dump of file C:\Redacted\Release\calcDLL.dll

File Type: DLL

Summary

    1000 .data
    1000 .rdata
    1000 .reloc
    1000 .rsrc
    2000 .text

I use Visual Studio Express 2013. Any idea on what I am missing?

Upvotes: 1

Views: 709

Answers (1)

stijn
stijn

Reputation: 35901

Evertything you show is sort of ok, so my guess is you just forgot to set the exports file in the project settings for the release configuration. Go to project properties->Linker->Input and set the Module Definition File.

Also: you have a memory leak because you don't delete calcObj. But actually there's no reason to use the heap here, just use Calc calcObj; on the stack. Also know that casting double to int is truncating, and have you thought of what will happen if the number is > 2^31 ?

Upvotes: 3

Related Questions