在cygwin上为getnetbyname链接哪个库?

时间:2014-10-26 23:39:03

标签: gcc cygwin undefined-reference

我正在尝试追踪更大的问题,这是简化的测试用例。

#include <netdb.h>
int main(int argc, char** argv)
{
 getnetbyname("localhost");
 return 0;
}

我编译为:

$ gcc -c -Werror -Wall foo.c

$ gcc foo.o
foo.o:foo.c:(.text+0x16): undefined reference to `getnetbyname'
collect2: error: ld returned 1 exit status

$ gcc foo.o -llwres
foo.o:foo.c:(.text+0x16): undefined reference to `getnetbyname'
collect2: error: ld returned 1 exit status

$ gcc foo.o -lwsock32
foo.o:foo.c:(.text+0x16): undefined reference to `getnetbyname'
collect2: error: ld returned 1 exit status

$ gcc foo.o -lmswsock
foo.o:foo.c:(.text+0x16): undefined reference to `getnetbyname'
collect2: error: ld returned 1 exit status

$ gcc foo.o -lamIcrazy
/usr/lib/gcc/i686-pc-cygwin/4.8.3/../../../../i686-pc-cygwin/bin/ld: cannot find -lamIcrazy
collect2: error: ld returned 1 exit status

不确定从何处开始,我很确定Perl使用此引用,但我无法遵循构建(尚未)。 gcc foo.o适用于Centos 6。

以下是带有getnetbyname符号的.a文件

Binary file /usr/lib/perl5/5.14/i686-cygwin-threads-64int/CORE/libperl.a matches
Binary file /usr/lib/w32api/libmswsock.a matches
Binary file /usr/lib/w32api/libwsock32.a matches

$ nm /usr/lib/w32api/libmswsock.a --demangle | grep -B 10 getnetbyname

dqsls00019.o:
00000000 b .bss
00000000 d .data
00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 i .idata$7
00000000 t .text
         U _head_lib32_libmswsock_a
00000000 I _imp__getnetbyname@4
00000000 T getnetbyname@4

$ nm /usr/lib/w32api/libwsock32.a --demangle | grep -B 10 getnetbyname

duegs00043.o:
00000000 b .bss
00000000 d .data
00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 i .idata$7
00000000 t .text
         U _head_lib32_libwsock32_a
00000000 I _imp__getnetbyname@4
00000000 T getnetbyname@4

1 个答案:

答案 0 :(得分:0)

根据https://cygwin.com/cygwin-api/std-notimpl.html,它看起来没有实现。

我一定误解了libwsock32.alibmswsock.a

的出口