Jump to content
  • Advertisement
Sign in to follow this  
Amazed

Setting up Dev-Cpp and WinSock lib's

This topic is 4776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

Share this post


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

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
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"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I had this same problem and found this in google. Thanks alot guys, it works.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I had to ! Thanks very much ! Kiss you all love you all ! THANKS !!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Very helpful post, thanks!
code on!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!