Setting up Dev-Cpp and WinSock lib's

Started by
6 comments, last by GameDev.net 18 years, 9 months ago
Hi everyone! I wrote a little HTTP page fetcher in Dev-Cpp, and I'm using Winsock as networking API. The code compiles just fine, but it doesn't link : it's missing all the Winsock functions. So I tried to add the options -lws2_32 and -lwsock32 as recommended on a site I google'd, but I still have the same problem. Just for the log, here some of my linking errors : main.o:main.cpp:(.text+0x149): undefined reference to `WSAStartup@8' main.o:main.cpp:(.text+0x1ce): undefined reference to `WSACleanup@0' main.o:main.cpp:(.text+0x205): undefined reference to `socket@12' main.o:main.cpp:(.text+0x241): undefined reference to `htons@4' ... main.o:main.cpp:(.text+0x476): undefined reference to `closesocket@4' main.o:main.cpp:(.text+0x47e): undefined reference to `WSACleanup@0' With and without the -l options, it's the same result. I'm stumped... I'd be really glad if you could point out what I'm missing. :) Thanks a lot!
Advertisement
If you include <winsock2.h> before you include <windows.h>, then you need to link with ws2_32.dll at runtime. Exactly how dev-cpp does that, I don't know, but it's likely to be something like "-lws2_32". You should turn on verbose mode and see what libraries it's actually looking for.

If you still can't get it to work, I suggest a support forum for Dev-CPP -- your problem is one of "how can I link with Windows API XXX", not a problem that has anything actually to do with networking. You're likely to get better answers in the right forum.
enum Bool { True, False, FileNotFound };
I tried to turn on verbose, to no avail. I'll go see what I can read on the Dev-Cpp forums.

Many thanks for your insight, hplus!
I do it this way:
goto Project menu and Click project options. Then click the parameters tab. Click the add library or object button. Find your dev-cpp\lib directory and find Dev-Cpp/lib/libws2_32.a press ok twice. It should work.

In my projects I have windows.h included above winsock2.h
If you use winsock2.h you may need to add the libwsock32.a library (located in Dev-Cpp/lib/) to the project through "Project Options->Parameters->Add library"
I had this same problem and found this in google. Thanks alot guys, it works.
I had to ! Thanks very much ! Kiss you all love you all ! THANKS !!!
Very helpful post, thanks!
code on!

This topic is closed to new replies.

Advertisement