kairon Posted December 8, 2002 Share Posted December 8, 2002 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 More sharing options...
0 azcodemonkey Posted December 9, 2002 Share Posted December 9, 2002 Are you linking with the winsock2 lib? ws2_32.lib, i believe. Link to comment Share on other sites More sharing options...
0 kairon Posted December 9, 2002 Author Share Posted December 9, 2002 Nope, thanks. How do I know what header files require me to link with what? Link to comment Share on other sites More sharing options...
0 freestyle Posted December 9, 2002 Share Posted December 9, 2002 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 More sharing options...
0 azcodemonkey Posted December 9, 2002 Share Posted December 9, 2002 Generally, it specifies in the API guide what files to link to, usually at the bottom of the page. Link to comment Share on other sites More sharing options...
Question
kairon
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:
Link to comment
Share on other sites
4 answers to this question
Recommended Posts