I am using MinGW compiler on Windows to compile my C++ application with sockets. My command for linking looks like:
g++.exe -Wall -Wno-long-long -pedantic -l
Put the -lws2_32 AFTER the list of object files - GCC searches libraries and object files in the order they appear on the command line.
-lws2_32
Just to help the other viewers out there:
gcc hello.c -o hello.o -lws2_32