5 Replies - 361 Views - Last Post: 29 March 2011 - 12:15 PM Rate Topic: -----

#1 rj.alaskan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 11

C++ and Winsock

Posted 28 March 2011 - 09:57 PM

I cannot seem to use Winsock properly to save my life. I have used several compilers but I always get weird errors. I am using Visual C++ 2008 express here

***
My Code
***
int main()
{
    cout<<"Initializing Winsock 1.1 or later...\n";
	
	// WINSOCK INITIALIZATION

WSADATA wsaData;

if (WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0) {
    // Check if major version is at least iReqWinsockVer
    if (LOBYTE(wsaData.wVersion) >= iReqWinsockVer) {
        // Network stuff here
    }
    else {
        // Required version not available
    }

    // Cleanup winsock
    if (WSACleanup()!=0) {
        // cleanup failed
		}
	}
else {
    //  startup failed
}
	// END WINSOCK INITIALIZATION

		system("PAUSE");
	}



***
Build Output
***
1>------ Build started: Project: ProjectX, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main
1>C:\Users\Rory\ProjectX\ProjectX\Debug\ProjectX.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\Rory\ProjectX\ProjectX\ProjectX\Debug\BuildLog.htm"
1>ProjectX - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




Thanks in advance for any help!

This post has been edited by rj.alaskan: 28 March 2011 - 09:58 PM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ and Winsock

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5354
  • View blog
  • Posts: 27,314
  • Joined: 10-May 07

Re: C++ and Winsock

Posted 28 March 2011 - 10:00 PM

I don't see any headers... did you include Winsock2.h?
Was This Post Helpful? 0
  • +
  • -

#3 rj.alaskan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 11

Re: C++ and Winsock

Posted 28 March 2011 - 11:45 PM

Sorry about that. Yes I did I omitted some code due to confidentiality :) I did include the correct header files.

This post has been edited by rj.alaskan: 28 March 2011 - 11:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 285
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: C++ and Winsock

Posted 28 March 2011 - 11:51 PM

Sounds like you might not have the libraries setup correctly.

http://msdn.microsof...z(v=vs.80).aspx

May be of help in understanding what that error really is.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: C++ and Winsock

Posted 29 March 2011 - 04:35 AM

Unresolved external symbols mean you failed to link the Winsock library to your program. You need to add I think it's ws2_32.lib to your list of input libraries to link.

EDIT: Should be .lib, not .dll

This post has been edited by JackOfAllTrades: 30 March 2011 - 03:30 PM

Was This Post Helpful? 1
  • +
  • -

#6 rj.alaskan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 11

Re: C++ and Winsock

Posted 29 March 2011 - 12:15 PM

View PostJackOfAllTrades, on 29 March 2011 - 04:35 AM, said:

Unresolved external symbols mean you failed to link the Winsock library to your program. You need to add I think it's ws2_32.dll to your list of input libraries to link.


I created a new project, and added the previous source file, then put

#pragma comment(lib, "ws2_32.lib")

And It worked fine. Thank you for the help! There was a dependency not met.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1