Thread: error LNK1120 & LNK2001:

  1. #1
    Registered User
    Join Date
    Mar 2004

    error LNK1120 & LNK2001:

    --------------------Configuration: ctl_one - Win32 Debug--------------------
    ctl_one.obj : error LNK2001: unresolved external symbol _ReportError
    Debug/ctl_one.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    ctl_one.exe - 2 error(s), 0 warning(s)


    here's my code

    #include <windows.h>
    #pragma comment(lib, "wsock32.lib")
    #include <winsock.h>
    #include <stdio.h>
    #define NETWORK_ERROR -1
    #define NETWORK_OK     0
    void ReportError(int, const char *);
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) {
    	WORD sockVersion;
    	WSADATA wsaData;
    	int nret;
    	SOCKET listeningSocket;
    	SOCKADDR_IN serverInfo;
    	SOCKET theClient;
    	sockVersion = MAKEWORD(1, 1);			// We'd like Winsock version 1.1
    	// We begin by initializing Winsock
    	WSAStartup(sockVersion, &wsaData);
    	// Next, create the listening socket
    	listeningSocket = socket(AF_INET,		// Go over TCP/IP
    			         SOCK_STREAM,   	// This is a stream-oriented socket
    				 IPPROTO_TCP);		// Use TCP rather than UDP
    	if (listeningSocket == INVALID_SOCKET) {
    		nret = WSAGetLastError();		// Get a more detailed error
    		ReportError(nret, "socket()");		// Report the error with our custom function
    		WSACleanup();				// Shutdown Winsock
    		return NETWORK_ERROR;			// Return an error value
    	// Use a SOCKADDR_IN struct to fill in address information
    	serverInfo.sin_family = AF_INET;
    	serverInfo.sin_addr.s_addr = INADDR_ANY;	// Since this socket is listening for connections,
    							// any local address will do
    	serverInfo.sin_port = htons(8888);		// Convert integer 8888 to network-byte order
    							// and insert into the port field
    	// Bind the socket to our local server address
    	nret = bind(listeningSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
    	if (nret == SOCKET_ERROR) {
    		nret = WSAGetLastError();
    		ReportError(nret, "bind()");
    		return NETWORK_ERROR;
    	// Make the socket listen
    	nret = listen(listeningSocket, 10);		// Up to 10 connections may wait at any
    							// one time to be accept()'ed
    	if (nret == SOCKET_ERROR) {
    		nret = WSAGetLastError();
    		ReportError(nret, "listen()");
    		return NETWORK_ERROR;
    	// Wait for a client
    	theClient = accept(listeningSocket,
    			   NULL,			// Address of a sockaddr structure (see explanation below)
    			   NULL);			// Address of a variable containing size of sockaddr struct
    	if (theClient == INVALID_SOCKET) {
    		nret = WSAGetLastError();
    		ReportError(nret, "accept()");
    		return NETWORK_ERROR;
    	else if ("1" == "1")
    	listeningSocket = theClient;
    	// Send and receive from the client, and finally,
    	// Shutdown Winsock
    	return NETWORK_OK;

    anyone knows what's wrong?

    using vc++6.0

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    You have the function prototype for the ReportError function but there is no code anywhere in the sample you provided for it. Solution... write some code for the ReportError function!
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    This is just a guess. I see your prototype for ReportError
    void ReportError(int, const char *);
    but I do not see the actual function. Is it contained somewhere else? If you have cut and pasted the code from some other source or used code from a book, it is common for the developer/author to have listed this function in another file or chapter.

    Just some thoughts.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  2. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM
  3. Book's code: Problematic
    By RoD in forum Game Programming
    Replies: 14
    Last Post: 01-21-2003, 09:08 AM
  4. Help with error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 04-17-2002, 09:36 AM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 03:24 AM