Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC regular DLL using shared MFC DLL module definition file (.def) question

MFC regular DLL using shared MFC DLL module definition file (.def) question

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncsharpc++visual-studio
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alchong
    wrote on last edited by
    #1

    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?

    M 1 Reply Last reply
    0
    • A alchong

      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?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      L 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        HA did I get hooked! I'm flopping around all over this boat[^]

        led mike

        R M 2 Replies Last reply
        0
        • L led mike

          HA did I get hooked! I'm flopping around all over this boat[^]

          led mike

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          :doh:

          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

          1 Reply Last reply
          0
          • L led mike

            HA did I get hooked! I'm flopping around all over this boat[^]

            led mike

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            *snicker* ;P

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups