MFC regular DLL using shared MFC DLL module definition file (.def) question
-
I'm learning how to build DLLs, and I've had some observations, and I was wondering if someone could provide me some insight. In Visual Studio 2005: 1) Created a new project 2) Using the project wizard created a MFC regular DLL using shared MFC DLL. (no other options selected) 3) Added a method to the default class generated by the wizard called "Execute" void Execute(); 4) Defined the method void CTestApp::Execute() { return; } Added the method for export in the module definition file (.def) LIBRARY "Test" EXPORTS Execute When I compile I get a link warnings/error: 1>Test.def : warning LNK4022: cannot find unique match for symbol 'Execute' 1>Test.def : warning LNK4002: "public: void __thiscall CTestApp::Execute(void)" (?Execute@CTestApp@@QAEXXZ) defined in .\debug\Test.obj 1>Test.def : warning LNK4002: "public: void __thiscall CDaoDatabase::Execute(unsigned short const *,int)" (?Execute@CDaoDatabase@@QAEXPBGH@Z) defined in C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib 1>Test.def : warning LNK4002: "public: void __thiscall CDaoDatabase::Execute(wchar_t const *,int)" (?Execute@CDaoDatabase@@QAEXPB_WH@Z) defined in C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib 1>Test.def : warning LNK4002: "public: virtual void __thiscall CDaoQueryDef::Execute(int)" (?Execute@CDaoQueryDef@@UAEXH@Z) defined in C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib 1>Test.def : error LNK2001: unresolved external symbol Execute 1>C:\Documents and Settings\fi507c\My Documents\Visual Studio 2005\Projects\Test\Debug\Test.lib : fatal error LNK1120: 1 unresolved externals So I've come across two solutions Solution 1: Instead of using a .def file, use __declspec(dllexport) to export. This solution makes sense, since it automatically creates the .def file for me. But I'm not sure what the issue with the .def file was. Was it due to name decoration? Solution 2: Instead of calling my method Execute, call it something different, like Axecute. This is somewhat odd to me, just by renaming the method to something else, the .def file works to export the function. Does it have to do with the some of the linker warning/error information? Wouldn't name decoration still cause an issue?
-
I'm learning how to build DLLs, and I've had some observations, and I was wondering if someone could provide me some insight. In Visual Studio 2005: 1) Created a new project 2) Using the project wizard created a MFC regular DLL using shared MFC DLL. (no other options selected) 3) Added a method to the default class generated by the wizard called "Execute" void Execute(); 4) Defined the method void CTestApp::Execute() { return; } Added the method for export in the module definition file (.def) LIBRARY "Test" EXPORTS Execute When I compile I get a link warnings/error: 1>Test.def : warning LNK4022: cannot find unique match for symbol 'Execute' 1>Test.def : warning LNK4002: "public: void __thiscall CTestApp::Execute(void)" (?Execute@CTestApp@@QAEXXZ) defined in .\debug\Test.obj 1>Test.def : warning LNK4002: "public: void __thiscall CDaoDatabase::Execute(unsigned short const *,int)" (?Execute@CDaoDatabase@@QAEXPBGH@Z) defined in C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib 1>Test.def : warning LNK4002: "public: void __thiscall CDaoDatabase::Execute(wchar_t const *,int)" (?Execute@CDaoDatabase@@QAEXPB_WH@Z) defined in C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib 1>Test.def : warning LNK4002: "public: virtual void __thiscall CDaoQueryDef::Execute(int)" (?Execute@CDaoQueryDef@@UAEXH@Z) defined in C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib 1>Test.def : error LNK2001: unresolved external symbol Execute 1>C:\Documents and Settings\fi507c\My Documents\Visual Studio 2005\Projects\Test\Debug\Test.lib : fatal error LNK1120: 1 unresolved externals So I've come across two solutions Solution 1: Instead of using a .def file, use __declspec(dllexport) to export. This solution makes sense, since it automatically creates the .def file for me. But I'm not sure what the issue with the .def file was. Was it due to name decoration? Solution 2: Instead of calling my method Execute, call it something different, like Axecute. This is somewhat odd to me, just by renaming the method to something else, the .def file works to export the function. Does it have to do with the some of the linker warning/error information? Wouldn't name decoration still cause an issue?
You'd need to fully qualify the name in the def file (like "CTestApp::Execute") because no Execute function exists in your project. That will get rid of all the warnings but then the name mangling will still prevent the link. Using __declspec(dllexport) is recommended over using the EXPORTS section of the def file. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You'd need to fully qualify the name in the def file (like "CTestApp::Execute") because no Execute function exists in your project. That will get rid of all the warnings but then the name mangling will still prevent the link. Using __declspec(dllexport) is recommended over using the EXPORTS section of the def file. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
:doh:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
*snicker* ;P
Mark Salsbery Microsoft MVP - Visual C++ :java: