afx.h causes trouble

Started by
3 comments, last by bakery2k1 17 years, 4 months ago
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; }
Advertisement
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
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.

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.
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"?

This topic is closed to new replies.

Advertisement