|
-
July 3rd, 2006, 01:35 PM
#1
error LNK2001
Hi,
I am a little puzzled about something. I am using msvs 2005 and I tried compiling a program that is a server client program so it uses winsock2.h. Since the program is a win32 console application, I figured I don't need the stdafx.cpp and stdafx.h file that msvs puts in all it's project. So I removed them from the project and took out the include from the main cpp file. Now I am getting this linker error:
soctest.obj : error LNK2001: unresolved external symbol __imp__accept@12
soctest.obj : error LNK2001: unresolved external symbol __imp__listen@8
and a bunch of others
I disabled "use precompiled headers in options" but I really don't know what is wrong with it. The funny thing is that if I put the stdafx.cpp in the project without using #include "stdafx.h", then I don't get this error. So what gives. Thanks a lot,
Amish
-
July 3rd, 2006, 01:50 PM
#2
Re: error LNK2001
 Originally Posted by axr0284
Since the program is a win32 console application, I figured I don't need the stdafx.cpp and stdafx.h file that msvs puts in all it's project.
Precompiled headers are used for faster compile times, and has nothing to do whether you create console applications or not.
 Originally Posted by axr0284
soctest.obj : error LNK2001: unresolved external symbol __imp__accept@12
soctest.obj : error LNK2001: unresolved external symbol __imp__listen@8
It seems that you forgot to link with "ws2_32.lib".
- petter
-
July 3rd, 2006, 04:33 PM
#3
Re: error LNK2001
Try this:
Use the Visual Studio Menu bar:-
Project>Settings>
click the link tab - and in the LHS drop down menu-> try selecting the 3 options i.e. Win32Release, Win32Debug & All Configurations.
See if it works?
Regards,
Bhushan.
-
July 3rd, 2006, 11:31 PM
#4
Re: error LNK2001
wildfrog was right on the money. After I added ws2_32.lib as an additional library to link in, it worked fine. I was wondering how'd you figure it out and how it is related to stdafx.cpp. Thanks a lot.
Amish
-
July 4th, 2006, 04:51 AM
#5
Re: error LNK2001
 Originally Posted by axr0284
After I added ws2_32.lib as an additional library to link in, it worked fine. I was wondering how'd you figure it out and how it is related to stdafx.cpp. Thanks a lot.
Well, IMO it's not related to stdafx.cpp/.h but if your project is configured to use precompiled headers then the compiler will look for stdafx.cpp and all code files should have a #include "stdafx.h." as the first line of code.
The accept/listen errors was solved simply by looking in the documentation. Both functions are part of ws2_32.lib, thus you'll need to link with that file.
- petter
-
July 4th, 2006, 10:26 AM
#6
Re: error LNK2001
I see. Thanks for taking the time to help me out.
Amish
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
|