Thread: Unresolved External Error (WSAStartup, WSACleanup)

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    361

    Unresolved External Error (WSAStartup, WSACleanup)

    Hullo,

    Beginning on my quest to learn Winsock, I've come across my first hitch. Sadly, it's pretty much my first line of code.

    According to...I forget which tutorial it was now, but there was one out there (I think BJee) that said the only header I need to include is:
    <winsock.h>

    I'm beginning to believe this is not the case. I've created a Win32 Console Application in VC++ 6.0.

    My code looks like:
    Code:
    #include <winsock.h>
    
    void main(void)
    {
    	const int WinsockVersion = 2;
    	
    	WSADATA wsaData;
    
    	if (WSAStartup(MAKEWORD(WinsockVersion, 0), &wsaData) == 0)
    	{
    		//Winsock goes in here
    	}
    
    	if (WSACleanup()!=0)
    	{
    	
    	}
    }
    But, sadly, it does not run, giving me these errors:

    Compiling...
    Main.cpp
    Linking...
    Main.obj : error LNK2001: unresolved external symbol _WSACleanup@0
    Main.obj : error LNK2001: unresolved external symbol _WSAStartup@8
    Debug/Winsock.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    Creating browse info file...

    No clue what I need to do. I'm thinking I may have missed some header? But no tutorials have told me which one.

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Your code is fine, and its not an error with your code. You have all the headers you need. Your problem is a Linker error, which is what the compiler does after its finished compiling. While the headers have been included, the actual code that does the work is nowhere to be found, it has to be included in your project.

    Winsock also comes with a library, wsock32.lib, which you link your project to with the line

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

    Put that line under your #includes, and you should be ok

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM
  5. Unresolved external symbols in OGL
    By Shadow12345 in forum Game Programming
    Replies: 4
    Last Post: 08-04-2002, 09:46 PM