• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3567
  • Last Modified:

error LNK2001: unresolved external symbol __imp__WSACleanup@0

Hi guys,

I am compiling my application in Release Mode (Debug Mode compiles no problem), and am getting these errors:

CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__connect@12
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__htons@4
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__inet_addr@4
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__setsockopt@20
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__socket@12
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__send@16
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__closesocket@4
CustomBrowserDlg.obj : error LNK2001: unresolved external symbol __imp__recv@16
Release/CustomBrowser.exe : fatal error LNK1120: 11 unresolved externals


Any idea how to fix these?

Cheers!
0
Cyber-Drugs
Asked:
Cyber-Drugs
  • 7
  • 4
  • 3
1 Solution
 
mahesh1402Commented:
You need to specify the winsock library project->settings->link.

In the project->settings->link, add this ws2_32.lib.

-MAHESH
0
 
bdunz19Commented:
Hey Cyber,

Make sure the statement #include <afxsock.h> is in your stdafx.h and is not surrounded by any #ifdef DEBUG_MODE or anything like that...

Heck try just including <afxsock.h> and see if that works.
0
 
mahesh1402Commented:
above are linker errors due to missing winsock library to link with ur project

So try adding ws2_32.lib to project->settings->link first.. that should solve your problem.

-MAHESH
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
bdunz19Commented:
MAHESH,

In MFC, I don't believe it is neccisary to include the winsock library as long as afxsock.h is included.
0
 
Cyber-DrugsAuthor Commented:
Mahesh,

I already have that file inside there, any other ideas?



Brandon,

When I add that to stdafx.h, I get 240+ errors...
0
 
mahesh1402Commented:
well I think you should link wsock32.lib or ws2_32.lib as its failing at linker level.
0
 
mahesh1402Commented:
well then may be missing is #include <winsock2.h>

-MAHESH
0
 
bdunz19Commented:
Haha, that's rather odd! Make sure there is not already included winsock.h.

I'm pretty sure afxsock.h is what you need.
0
 
mahesh1402Commented:
>>I already have that file inside there, any other ideas?

are you sure you are linking with : ws2_32.lib
0
 
Cyber-DrugsAuthor Commented:
Brandon, I'll have a quick look and see...

Mahesh, I just double checked, and yes I am linking with that file already.
0
 
mahesh1402Commented:
well afxsock.h includes #pragma comment(lib, "wsock32.lib") statement which equal to linking with wsock32.lib.. as I said before you need to link with that anyway with afxsock.h or manually linking !!!
0
 
Cyber-DrugsAuthor Commented:
Brandon,

I replaced winsock.h to afxsock.h

It now compiles with other errors (which I expected), cheers!
0
 
bdunz19Commented:
Yeah, I just realized that because you are linking manually to ws2_32.lib, that is most likely going to cause some problems. So either stick to ws2_32.lib/winsock.h or remove those and simply include afxsock.h

Hope that solves it
0
 
mahesh1402Commented:
if that working with afxsock.h, it should also work with manually linking with wsock32.lib and without afxsock.h !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now