CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2000
    Posts
    1,471

    A strange problem related to def file.

    I got a linker error "error LNK2001: unresolved external symbol "public: virtual int __thiscall XXXClass::XXXXFunction(class CWnd *,struct IMyStruct * const)" (?XXXXFunction@XXXClass@@UAEHPAVCWnd@@QAUIMyStruct@@@Z)"
    Recently I modified XXXXFunction and added one more parameter. Now XXXXFunction is defined as
    Code:
    XXXXFunction(CWnd *,IMyStruct * const, int)
    I checked both header file and source file and I am sure the definition of XXXXFunction has already updated in both header file and source file. On the other hand, I use def file in my project. The problem is that XXXXFunction is still defined as
    Code:
    ?XXXXFunction@XXXClass@@UAEHPAVCWnd@@QAUIMyStruct@@@Z
    Obviously the definition of XXXXFunction in def file doesn't match with the one in header file and source file. But since I got a linker error, so I couldn't get a dll. As the result, I don't know how to modify def file in order to match header file and source file. Any idea how to fix this problem? Thanks for your inputs.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: A strange problem related to def file.

    Quote Originally Posted by dullboy View Post
    I use def file in my project. The problem is that XXXXFunction is still defined as
    Code:
    ?XXXXFunction@XXXClass@@UAEHPAVCWnd@@QAUIMyStruct@@@Z
    Obviously the definition of XXXXFunction in def file doesn't match with the one in header file and source file.
    Then why didn't you rebuild this DLL?

    Besides, it is not clear where your class is defined: in exe or dll? And where and how is this XXXXFunction method called from?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: A strange problem related to def file.

    Go to your debugging linker options/settings and set "Generate Map File" to "Yes" (this correspond to /MAP linker option).
    Make a build then search for generated .map file. Open it in an editor, search for your function name, let's say "XXXXFunction", copy the found decorated function, then paste it in the EXPORTS section of your .def file.

    Alternatively, you can get rid of exporting via .def files, by using __declspec(dllexport) directive.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: A strange problem related to def file.

    Quote Originally Posted by dullboy View Post
    I got a linker error "error LNK2001: unresolved external symbol "public: virtual int __thiscall XXXClass::XXXXFunction(class CWnd *,struct IMyStruct * const)" (?XXXXFunction@XXXClass@@UAEHPAVCWnd@@QAUIMyStruct@@@Z)"
    Recently I modified XXXXFunction and added one more parameter. Now XXXXFunction is defined as
    Code:
    XXXXFunction(CWnd *,IMyStruct * const, int)
    The signature in the error message (?XXXXFunction@XXXClass@@UAEHPAVCWnd@@QAUIMyStruct@@@Z) is still looking for the function without your int - it's looking for
    Code:
    XXXXFunction(CWnd *,IMyStruct * const)
    Since you didn't say what version of Visual Studio (or VC) you're using try closing the project, then delete any file of type .aps, .clw, .ncb, .sdf, and .suo, then rebuild the project.

    Perhspa that might help.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  5. #5
    Join Date
    Aug 2000
    Posts
    1,471

    Re: A strange problem related to def file.

    Quote Originally Posted by ovidiucucu View Post
    Go to your debugging linker options/settings and set "Generate Map File" to "Yes" (this correspond to /MAP linker option).
    Make a build then search for generated .map file. Open it in an editor, search for your function name, let's say "XXXXFunction", copy the found decorated function, then paste it in the EXPORTS section of your .def file.

    Alternatively, you can get rid of exporting via .def files, by using __declspec(dllexport) directive.
    It works! Thank you very much! But I had to remove the entry for XXXXFunction in def file first in order to build the project successfully. I couldn't figure out why removing this entry make build successful. Do you know why? Then I am able to generate the map file as you suggested.

  6. #6
    Join Date
    Aug 2000
    Posts
    1,471

    Re: A strange problem related to def file.

    Quote Originally Posted by VictorN View Post
    Then why didn't you rebuild this DLL?

    Besides, it is not clear where your class is defined: in exe or dll? And where and how is this XXXXFunction method called from?
    Actually I did rebuild the dll but it failed. My class is defined in a MFC extension dll and is exported by using AFX_EXT_CLASS. Thanks.

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: A strange problem related to def file.

    Quote Originally Posted by dullboy View Post
    It works! Thank you very much! But I had to remove the entry for XXXXFunction in def file first in order to build the project successfully. I couldn't figure out why removing this entry make build successful. Do you know why? Then I am able to generate the map file as you suggested.
    First, keep in mind that .DEF file isn't generated by IDE.
    So, if you write something wrong in it, most possible you get an error and the fault is yours.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: A strange problem related to def file.

    Quote Originally Posted by dullboy View Post
    Actually I did rebuild the dll but it failed. My class is defined in a MFC extension dll and is exported by using AFX_EXT_CLASS. Thanks.
    Actually, the class that is defined with AFX_EXT_CLASS never needs a DEF file. Moreover, DEF file overrides __declspec(dllexport) and this way is able to introduce hardly explainable malfunctioning.
    Best regards,
    Igor

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: A strange problem related to def file.

    One aside advice: avoid as much as possible to modify the existing interface of a DLL.
    Generally, DLLs are intended to be shared between applications so, if you change the interface, then all application which are using it must be modified and rebuilt.
    Beside, it's possible, some of them would prefer better to stay "backward" and use the old interface.

    So, if you want to add some new functionality to, let's say XXXXFunction, and that requires an additional parameter, do not modify the existing function.
    Let XXXXFunction as it is and add a new function, let's say it XXXXFunctionEx.
    This way you do not change the old interface so not all client aplications have to be modified and rebuilt.
    What you further do behind, in the functions implementation, doesn't matter too much from client point of view.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured