-
July 2nd, 2012, 05:19 PM
#1
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.
-
July 3rd, 2012, 01:23 AM
#2
Re: A strange problem related to def file.
Originally Posted by dullboy
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
-
July 3rd, 2012, 05:39 AM
#3
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.
-
July 3rd, 2012, 05:51 AM
#4
Re: A strange problem related to def file.
Originally Posted by dullboy
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
-
July 3rd, 2012, 10:51 AM
#5
Re: A strange problem related to def file.
Originally Posted by ovidiucucu
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.
-
July 3rd, 2012, 11:02 AM
#6
Re: A strange problem related to def file.
Originally Posted by VictorN
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.
-
July 3rd, 2012, 12:37 PM
#7
Re: A strange problem related to def file.
Originally Posted by dullboy
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.
-
July 3rd, 2012, 02:38 PM
#8
Re: A strange problem related to def file.
Originally Posted by dullboy
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
-
July 4th, 2012, 03:52 AM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|