Search code examples
c++dlllinkernmakecl

VC++ DLL compilation using NMAKE


I have a DLL file compiled using Visual Studio 2005 and it works perfectly, when I call those functions(in DLL) from a C# program. But if I compile the same program using NMAKE , it compiles successfully but it doesn't work with the C# program. I get a "DLL NOT FOUND EXCEPTION" or "DLL IS CORRUPT".

P.S: I copied all the compiler options and Linker options from the Original project file and used it in the MakeFile but still of no use. What am I missing out here?

Compiler and Linker options as follows:

Compiler opt: /O2 /Ob1 /D "WIN32" /D "NDEBUG" /D "_WRITE_LOGS" /D "_VC80_UPGRADE=0x0700" /D "_WINDLL" /D "_MBCS" /Fo"obj\\" /FD /EHsc /MD /W3 /nologo /c /Gz /TP /errorReport:prompt 

Linker opt: /OUT:"dll/XXX.dll" /INCREMENTAL:NO /NOLOGO /DLL /DEF:"src\XXX.def" /DELAY:UNLOAD /MACHINE:X86 /ERRORREPORT:PROMPT mqrt.lib ..(other lib files)..

Edit: If I use dumpbin, the size of "HEADERS","EXPORTS","SYMBOLS" are all less in the DLL compiled using NMAKE than the DLL compiled using Visual studio !


Solution

  • I figured out my fault. I just didn't include a part of the actual compilation. The important part I guess.

    Embedding the manifest file to the DLL

    The Mt.exe file is a tool that generates signed files and catalogs. I found this link and it was so useful.

    P.S: I learnt this. The three important parts of compiling a DLL are,

    • COMPILER(CL.exe)
    • LINKER(LINK.exe)
    • Embedding manifest (MT.exe)