Sign in to follow this  
Amazed

Setting up Dev-Cpp and WinSock lib's

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this