Sign in to follow this  
Amazed

Setting up Dev-Cpp and WinSock lib's

Recommended Posts

Amazed    122
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
hplus0603    11356
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
Amazed    122
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
chad_420    290
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
Patbert    462
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   
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   
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

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