2014-10-26 61 views
0

我想追查一個更大的問題,這裏是簡化的測試用例。在cygwin上爲getnetbyname鏈接哪個庫?

#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符號

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 [email protected] 
00000000 T [email protected] 

$ 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 [email protected] 
00000000 T [email protected] 

回答