getaddrinfo Errors (linker problems)

So, I have recently been trying to delve into Winsock2. I was doing a tutorial and all was going well. I linked WS2_32.lib, and I got my code to compile, until I had to use "getaddrinfo()". Now my compiler is saying that it doesn't know what getaddrinfo() is, even though it is in the winsock2 header. The exact error I am seeing is :

[Linker error] undefined reference to `getaddrinfo@16'

I'm assuming its saying that it doesn't know what getaddrinfo is at line 16. Also, I am using DevC++. Thank you to anyone who can help me out with this.
i believe i can help you.

the undefined reference means that the linker could not resolve an address for that function. if you have the right header, it will not give you a compile error, because you have the prototype for that function in the header, but when the linker goes to that library and tries to get an address for that function, if you are not linking to the right library, it will not find an address and give you an error then.

DevC++ (imo) is the best IDE out there right now. their libraries are titled differently than in other IDE's however, and linking to WS2_32.lib will do you no good.
I am almost positive that under devcpp the library that you are looking for is "libws2_32.a"

try linking to that and let me know if that was the problem.

edit: you may also need the <ws2tcpip.h> header, which i believe automatically includes <winsock2.h> with it!
Last edited on
Topic archived. No new replies allowed.