Sign in to follow this  
JohnsonGPS

afx.h causes trouble

Recommended Posts

JohnsonGPS    109
I created a Win32 Console project with Microsoft Visual C++.NET. After I added #include <afx.h>, I got the following error message. Does it mean that I cannot use afx.h in Win32 Console project? ProcessLogs error LNK2019: unresolved external symbol __endthreadex referenced in function "void __stdcall AfxEndThread(unsigned int,int)" (?AfxEndThread@@YGXIH@Z) ProcessLogs error LNK2019: unresolved external symbol __beginthreadex referenced in function "public: int __thiscall CWinThread::CreateThread(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES *)" (?CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRIBUTES@@@Z) ProcessLogs fatal error LNK1120: 2 unresolved externals Thanks. Johnson #include "stdafx.h" #include <afx.h> int _tmain(int argc, _TCHAR* argv[]) { return 0; }

Share this post


Link to post
Share on other sites
Palidine    1315
it means you're not linking to the correct library. You need to link to whatever library defines the symbols declared via afx.h. check msdn for documentation for which libs you need.

-me

Share this post


Link to post
Share on other sites
bakery2k1    712
In order to use these thread functions, you need to link to the multithreaded version of the C runtime library.

Project > Properties > C/C++ > Code Generation > Runtime Library. Change from whichever single threaded version you are currently using to the corresponding multithreaded version.

Share this post


Link to post
Share on other sites
JohnsonGPS    109

After switching from single threaded Runtime library to the multithreaded one, I got the following error.

ProcessLogs warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
ProcessLogs error LNK2001: unresolved external symbol ___argvProcessLogs error LNK2001: unresolved external symbol ___argc
ProcessLogs fatal error LNK1120: 3 unresolved externals


Johnson


#include "stdafx.h"
#include "afx.h"

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}


____________________________________________________________________________

In order to use these thread functions, you need to link to the multithreaded version of the C runtime library.

Project > Properties > C/C++ > Code Generation > Runtime Library. Change from whichever single threaded version you are currently using to the corresponding multithreaded version.

Share this post


Link to post
Share on other sites
bakery2k1    712
This code:


#include "afx.h"

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}



compiles and links fine for me, using VS 2003. All I did was create a new, empty console project, and switch to use the multithreaded CRT.

What else do you have in your project?
What are the contents of your "stdafx.h"?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this