35

When generating a COM dll with VisualStudio, all I really need is the DllCanUnloadNow symbol (and three related ones) to be exported from the dll itself. Nobody is going to link against my library, so I'm not (at all) interested in a .lib file, nor in an .exp file.

However, I don't manage to inhibit creation of these files. (note: I do know how it's possible to remove them in a post-build step)

These are my linker arguments:

/OUT:"u:/cada-nt/bin/PData.dll" 
/INCREMENTAL:NO 
/NOLOGO 
/DLL 
/MANIFEST:NO 
/DEF:"PData.def" 
/DEBUG 
/PDB:"u:/cada-nt/pdb/PData.pdb" 
/ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
                    advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
                    odbc32.lib odbccp32.lib

The question:

  • Has anyone succeeded in not generating the .lib and .exp files?
  • Does anyone know why these files are generated?
xtofl
  • 40,723
  • 12
  • 105
  • 192

6 Answers6

18

Visual Studio's linker has an /IMPLIB option that allows you to specify the output location for your .lib and .exp files.

You can modify this option in a project's properties:

Configuration Properties > Linker > Advanced > Import Library

You might set it to the following, for example:

$(Configuration)\$(TargetName).lib

The linker will create the .exp file using the same name as the .lib.

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
garkin
  • 458
  • 5
  • 10
  • 11
    Thats not what the OP asked for. He does not want those files created by the linker at all, not in a different folder – philk Jul 24 '13 at 10:51
5

There some functions inside COM library declared with as __declspec(dllexport). It means that they are exported (may be used by GetProcAdress function) and linker thinks that there is a need to link with this dynamic library (no matter it is exe or dll - in general the structure is the same) and creates *.lib and *.exp file.

to avoid creation of these files you need to remove all __declspec(dllexport) from functions declarations

Sergey Maruda
  • 193
  • 1
  • 6
3

/NOIMPLIB will prevent generation of the .lib file. I don't know how to avoid the .exp file.

0xF
  • 3,214
  • 1
  • 25
  • 29
2

Not sure how to turn them off, but you can make a post-build step to remove them, like this:

del $(OutDir)\$(ProjectName).lib
del $(OutDir)\$(ProjectName).exp

(on VS2008 it's [Project]->[Properties], then Configuration Properties->Build Events->Post-Build Events)

(note I realise you know how to do this, but this answer may help the next googler...)

demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • 6
    A side effect of this workaround is that compilation will happen every time, because the compiler wants to recreate the files. – RC-1290 May 08 '15 at 14:56
-1

I guess you can hook on kernel32.dll CreateFile/WriteFile/CloseHandle and just redirect that directly into nul.

excitoon
  • 328
  • 3
  • 11
-6

why is it a problem to generate these files? Surely if people aren't going to link directly to them all you need to do is not distribute those files and simply distribute the DLL only.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • 14
    There is no urgent problem. I even have a workaround. It's just useless that the linker generate them. The files are automatically on the output folder, next to the dll that I need to distribute. It clutters. It annoys. – xtofl Sep 16 '09 at 09:08
  • 1
    TBH I'd reckon its so low down on the list of things to do, for obvious reasons, that noone has ever bothered doing it. – Goz Sep 16 '09 at 09:49
  • 14
    -1: this is a perfectly reasonable request. I request it too, for the same reasons, those files are annoying. – demoncodemonkey Aug 02 '10 at 16:03
  • 3
    @demoncodemonkey: Get used to it. I suspect you also want to get rid of those annoying obj files too ...It shocks me that some people worry about something so inconsequential and, in the end, utterly useful. – Goz Aug 02 '10 at 22:45
  • 7
    No the obj files are not so annoying because they go in the intermediate directory. The exp and lib are in my nice clean output directory... and that's the difference. – demoncodemonkey Aug 03 '10 at 11:00
  • 4
    My use-case is 100% identical. I would like to not generate these files. – Vinnie Falco Apr 15 '12 at 17:00
  • @Goz for me it is a problem since while the linker support generation R10000, it doesn’t support it for static libraries. – user2284570 Jul 28 '15 at 18:59