Undefined reference to getaddrinfo

前端 未结 3 497
孤独总比滥情好
孤独总比滥情好 2020-12-06 12:07

I have been getting this error for quite some time now and Google has not been of much help either.

I am a newbie to Winsock programming and trying to learn from onl

相关标签:
3条回答
  • 2020-12-06 12:37

    WindowsXP was defined in w32api.h, you have to #include <w32api.h> before your #define WINVER.

    0 讨论(0)
  • 2020-12-06 12:42

    Isn't it the same problem as here ?

    http://programmingrants.blogspot.com/2009/09/tips-on-undefined-reference-to.html

    Basically do not forget to link with Ws2_32.lib (the message is from the linker, so that's should be the reason) but you seem to be doing that already.

    ... if you're working with an old version of windows programming tools say to it you have a version higher than XP by putting #define _WIN32_WINNT 0x0501 before including headers (unlikely to still be necessary nowaday, but maybe).

    The could be other simple problems. Normal (Unix) convention for libraries is to prepend them with lib. Henceforth, meaning for -lWS32_32 would be to search for a file whose name is libWS32_32.a. It is likely it does not find it because it's missing the path to the directory containing the library. You could add a -L followed by the path to the correct directory. Alternatively you do not even need -l to link with a library, just putting the full path to the library (in this case the real name of the file as it appears on filesystem) should also work.

    The problem can also be path related. For instance problems can occurs if path to library contains spaces. If this is so you can try putting you library files in a directory with a simpler name.

    Please give use some feedback of your actual configuration (in which directory is the library file) and what you actually tried. You could also tries setting LIBS and LIBPATH environment variables (simplest way is probably to do that from a makefile).

    0 讨论(0)
  • 2020-12-06 12:52

    http://msdn.microsoft.com/en-us/library/ms738520(v=vs.85).aspx

    Take a look at the stuff under "remarks". It is possible that you are trying to use an ANSI-C version of the function when you aren't compiling as ANSI-C.

    0 讨论(0)
提交回复
热议问题