Sign in to follow this  

afx.h causes trouble

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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

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
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

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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