1

trying to compile a windows socket, having linker issues

makefile

EXECUTABLES=CLIMain
SRC=CLIMain.c SerialDriverWin.c CLItext.c ReadThreadWin.c TESTterminalOpcode.c SocketWin.c
OBJ=CLIMain.o SerialDriverWin.o CLItext.o ReadThreadWin.o TESTterminalOpcode.o SocketWin.o

CC=gcc
CFLAGS= -lws2_32

all: $(EXECUTABLES)

CLIMain: $(OBJ)
    $(CC) $(SRC) $(CFLAGS) -o CLIMain

clean:
    del *.o
    del CLIMain.exe

Output

C:\cli_terminal>mingw32-make
gcc -lws2_32   -c -o CLIMain.o CLIMain.c
gcc -lws2_32   -c -o SerialDriverWin.o SerialDriverWin.c
gcc -lws2_32   -c -o CLItext.o CLItext.c
gcc -lws2_32   -c -o ReadThreadWin.o ReadThreadWin.c
gcc -lws2_32   -c -o TESTterminalOpcode.o TESTterminalOpcode.c
gcc -lws2_32   -c -o SocketWin.o SocketWin.c
gcc CLIMain.c SerialDriverWin.c CLItext.c ReadThreadWin.c TESTterminalOpcode.c SocketWin.c -lws2_32 -o CLIMain
C:\Users\ilia\AppData\Local\Temp\ccAmUZpG.o:SocketWin.c:(.text+0x229): undefined reference to `getaddrinfo'
C:\Users\ilia\AppData\Local\Temp\ccAmUZpG.o:SocketWin.c:(.text+0x2b4): undefined reference to `freeaddrinfo'
C:\Users\ilia\AppData\Local\Temp\ccAmUZpG.o:SocketWin.c:(.text+0x31b): undefined reference to `freeaddrinfo'
C:\Users\ilia\AppData\Local\Temp\ccAmUZpG.o:SocketWin.c:(.text+0x348): undefined reference to `freeaddrinfo'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\ilia\AppData\Local\Temp\ccAmUZpG.o: bad reloc address 0x20 in s
ection `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
makefile:14: recipe for target 'CLIMain' failed
mingw32-make: *** [CLIMain] Error 1

SocketWin.h

#ifndef SOCKETWIN_H
#define SOCKETWIN_H

int winSocket();
void shutdownSocket();

#endif

includes for SocketWin.c

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <winsock2.h> // needed for socket
#include <ws2tcpip.h> // needed for socket
#include <iphlpapi.h> // needed for socket
#include <stdlib.h>
#include <stdio.h>

#pragma comment(lib, "Ws2_32.lib") // needed for socket

I have tried reordering the includes for SocketWin.c, first including winsok2.h then windows.h and all possible combinations. no luck what so ever. I am using mingw to compile this. The SocketWin.c file just creates a socket and starts a thread for the communication for that socket. please let me know if I need to provide more code.

  • possible duplicate of [MinGW linker error: winsock](http://stackoverflow.com/questions/2033608/mingw-linker-error-winsock) – IInspectable Feb 01 '15 at 21:58
  • I did in the make file, i placed it in both places just to be sure, still no. – deathlok0000 Feb 01 '15 at 22:03
  • Are you using vanilla MinGW? If so, try changing to MinGW-w64. Vanilla MinGW is stuck in 1999; `getaddrinfo()` is documented as being new in Vista. – andlabs Feb 01 '15 at 23:24
  • didnt work on w64 either. also looked at this [Older Post](http://stackoverflow.com/questions/2033608/mingw-linker-error-winsock) my makefile accounts for linking the library, just for over kill I compiled each file individually and then tried linking it like it suggestions in the linked post. still does not work.... – deathlok0000 Feb 02 '15 at 19:02
  • [problem solved](http://stackoverflow.com/questions/5220190/undefined-reference-to-getaddrinfo) – deathlok0000 Feb 02 '15 at 22:30

0 Answers0