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.