• 0

[c] Undefined Reference To


Question

I'm just trying to make a simple sockets program on windows and came across

" [Linker error] undefined reference to `socket@12"

D:\Documents and Settings\Jon\Desktop\New Folder\Makefile.win

[build Error] [Project3.exe] Error 1

when trying to compile, heres my code:

#include <stdio.h>
#include <stdlib.h>
#include <winsock.h>
/* Defines */
#define af PF_INET /* ddress format spec */
#define type SOCK_STREAM /* type specification */
#define protocol 0 /* protocol */

int main(int argc, char *argv[])
{   
  int new_socket = socket(af, type, protocol);
  
 /* if (new_socket = INVALID_SOCKET) */
  /*{ error checking to see if the socket failed
    WSAGetLastError();
    exit(EXIT_FAILURE);
  }
  
  printf("Socket worked");
  closesocket(new_socket); Close socket */
  exit(EXIT_SUCCESS);
}

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
Nope, thanks. How do I know what header files require me to link with what?

You could try MSDN if you don't already have it installed.

If you use MSDN, and look-up the socket() function, down at the bottom of the page it will list what headers and libs are needed for the function.

You will also see that for the socket() function you NEED to issue the WSAStartup() function BEFORE you do any socket communication.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.