CodeBlocks: Undefined reference to getaddrinfo()

By nick | Code
12 Dec 2011

If you’re encountering the error “Undefined reference to getaddrinfo()” he’s how to solve the problem.  It seems the winsock examples on the MSDN site are very much intended for use with Visual C and therefore you may have to do a few additional things to get everything working correctly.

 

Firstly you’ll need to add a few Link Settings.  In codeblocks you can find the settings page shown below under Project/Build Options/Link Settings.

Codeblocks Linker Settings

 

As you can see above, you need to add “libws2_32.a” to the Link Libraries and “-lwsock32″ to the linker options.

 

Additionally:

You may need to add the following to your code:

#define _WIN32_WINNT 0×501

4 Comments

  1. MarkusR says:

    Not quite working yet. I’m following the MSDN article pretty closely but the code still gives the same error after your fix.

Leave a Reply