Link to home
Start Free TrialLog in
Avatar of barkhashah
barkhashah

asked on

error LNK2001: unresolved external symbol ___argv

Hi All,
 Can anyone tell me how to resolve the following linking error:

nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(viewedit.obj) : error LNK2019: unresolved external symbol __mbctype referenced in function "protected: long __thiscall CEditView::OnFindReplaceCmd(unsigned int,long)" (?OnFindReplaceCmd@CEditView@@IAEJIJ@Z)
.\Debug/XAgentISAPIExtension.dll : fatal error LNK1120: 3 unresolved externals

Configuration Properties are set as follows:
1) Use MFC in a shared Dll
2)Runtime library = Multi-threaded Debug DLL (/MDd)
Avatar of nonubik
nonubik

nafxcwd.lib is MFC Static-Link Library, Debug version.
Are you sure that you're usein MFC in a shared DLL? Have you changed your project setting from static MFC to shared?
If so, in the linker settings for your project, if you have nafxcwd.lib, change it to mfcXXd.lib
Avatar of barkhashah

ASKER

yes i am sure i am using shared mfc libraries. Can you please make me clear about the solution you mentioned in including mfcXXd.lib.
Thanks
project properties->linker->'Input' page. Do you have nafcwd.lib in the 'Additional Dependencies' field? Do you have anything there?
I dont have anything in the additional dependencies tab.
By using verbose:lib option i get to know all the libraries that application will use.
One of them is
Searching C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\lib\nafxcwd.lib:

When i have already used shared mfc debug library then how come is the vc++ compiler adding this static one.
Please tell me what to ignore and what to include in the library.
Sorry to bother you again.
I really don't know how that you're linking with nafcwd.lib
Try putting it in the 'Ignore specific library' field and build again.
I cant do that because i get umpteen linking errors:
 LNK2001: unresolved external symbol __afxForceEXCLUDE

LNK2001: unresolved external symbol "void __stdcall AfxThrowOleException(long)" (?AfxThrowOleException@@YGXJ@Z)

error LNK2019: unresolved external symbol "void __stdcall AfxThrowMemoryException(void)" (?AfxThrowMemoryException@@YGXXZ) referenced in function "void __stdcall ATL::AtlThrow(long)" (?AtlThrow@ATL@@YGXJ@Z)
do you have defined _AFXDLL in your 'Preprocessor definitions' under C++ page?
NO. I tried putting this also but to no avail.
Can you just build a new MFC dll project with your desired settings and then add all your files (re/sources, headers, etc) in it?
I'm clueless right now...

hmm, how did exactly you get this linker error? I mean after what operation
did your dll ever linked errorless?
okay i will do . I am myself lost as to when i started getting this linking error.
Let me make a fresh application and try my hands out.
Thanks very much for your help.
I have a dll with following settings:
Use of MFC: Use standard windows library

When i compile and link the application, everything runs successfully.

Now i change the settings as follows:
Use of MFC: Use MFC in a shared Dll


I get the following linking error:
IsapiRequest.obj : error LNK2019: unresolved external symbol __imp__RevertToSelf@0 referenced in function "public: int __thiscall ISAPI_REQUEST::UnimpersonateClient(void)" (?UnimpersonateClient@ISAPI_REQUEST@@QAEHXZ)
IsapiRequest.obj : error LNK2019: unresolved external symbol __imp__SetThreadToken@8 referenced in function "public: int __thiscall ISAPI_REQUEST::ImpersonateClient(void)" (?ImpersonateClient@ISAPI_REQUEST@@QAEHXZ)

I then go to the code and comment these functions and run them again with the later settings.
To my surprise the code compiles successfully even with the later settings. Now this function is not using any thing new( MFC based) that other functions in the code using .
????????
Ah! These 2 functions are further returning a parameter by calling a function in winbase.h whose calling convention is __stdcall. However, in my application the project settings are __cdecl (/Gd).
Is there any clue you get?????
So what's the question?
Suppose there is a function whose calling convention is __cdecl
.
This function returns with another function whose calling convention is __stdcall.
This leads to a linking error.
How do i make the first function's convention changed to the __stdcall.

Ex:
int fun()  // calling convention __cdecl
{
  return abc()  // calling convention __stdcall ( windows function defined in winbase.h
}
try changing to /Gz
Are you sure you link against Advapi32.lib ?
That's where RevertToSelf and SetThreadToken are
Hey how did you come to know that my application is finally calling RevertToSelf and SetThreadToken functions.
Magic! :)




You said that:
>IsapiRequest.obj : error LNK2019: unresolved external symbol __imp__RevertToSelf@0 referenced in function "public: int >__thiscall ISAPI_REQUEST::UnimpersonateClient(void)" (?UnimpersonateClient@ISAPI_REQUEST@@QAEHXZ)
My problem is solved by adding Advapi32.lib in the settings.
This is great. Thanks very much.
Great!
Good catch. Thanks again
ASKER CERTIFIED SOLUTION
Avatar of nonubik
nonubik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial