当前位置: 技术问答>linux和unix
关于《unix网络编程》与《用tcp/ip进行网际互联-第三卷》的示例的编译问题?
来源: 互联网 发布时间:2015-09-11
本文导语: 我在运行《unix网络编程》第一卷的代码时,./configure后, 在lib文件夹下运行make,结果如下: [root@localhost unpv12e]# cd lib [root@localhost lib]# make gcc -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c In file included f...
我在运行《unix网络编程》第一卷的代码时,./configure后,
在lib文件夹下运行make,结果如下:
[root@localhost unpv12e]# cd lib
[root@localhost lib]# make
gcc -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c
In file included from connect_nonb.c:1:
unp.h:114: redefinition of `struct in_pktinfo'
make: *** [connect_nonb.o] Error 1
请问怎末办?
我在运行《用tcp/ip进行网际互联-第三卷》的代码时,在example目录下运行make,出现如下错误:
root@localhost a]# cd examples
[root@localhost examples]# make
cc -W -pedantic -ansi -g -c -o connectTCP.o connectTCP.c
cc -W -pedantic -ansi -g -c -o connectUDP.o connectUDP.c
cc -W -pedantic -ansi -g -c -o connectsock.o connectsock.c
cc -W -pedantic -ansi -g -c -o errexit.o errexit.c
cc -W -pedantic -ansi -g -c -o TCPecho.o TCPecho.c
cc -o TCPecho -W -pedantic -ansi -g TCPecho.o connectTCP.o connectUDP.o connectsock.o errexit.o
TCPecho.o(.text+0x17a): In function `TCPecho':
/root/c/a/a/examples/TCPecho.c:66: undefined reference to `errno'
connectsock.o(.text+0x160): In function `connectsock':
/root/c/a/a/examples/connectsock.c:69: undefined reference to `errno'
connectsock.o(.text+0x197):/root/c/a/a/examples/connectsock.c:73: undefined reference to `errno'
collect2: ld returned 1 exit status
make: *** [TCPecho] Error 1
代码中有extern int errno
但为甚末找不到呢?
关于这两本书的代码编译似乎许多人都有问题,请高手赐教!
在lib文件夹下运行make,结果如下:
[root@localhost unpv12e]# cd lib
[root@localhost lib]# make
gcc -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c
In file included from connect_nonb.c:1:
unp.h:114: redefinition of `struct in_pktinfo'
make: *** [connect_nonb.o] Error 1
请问怎末办?
我在运行《用tcp/ip进行网际互联-第三卷》的代码时,在example目录下运行make,出现如下错误:
root@localhost a]# cd examples
[root@localhost examples]# make
cc -W -pedantic -ansi -g -c -o connectTCP.o connectTCP.c
cc -W -pedantic -ansi -g -c -o connectUDP.o connectUDP.c
cc -W -pedantic -ansi -g -c -o connectsock.o connectsock.c
cc -W -pedantic -ansi -g -c -o errexit.o errexit.c
cc -W -pedantic -ansi -g -c -o TCPecho.o TCPecho.c
cc -o TCPecho -W -pedantic -ansi -g TCPecho.o connectTCP.o connectUDP.o connectsock.o errexit.o
TCPecho.o(.text+0x17a): In function `TCPecho':
/root/c/a/a/examples/TCPecho.c:66: undefined reference to `errno'
connectsock.o(.text+0x160): In function `connectsock':
/root/c/a/a/examples/connectsock.c:69: undefined reference to `errno'
connectsock.o(.text+0x197):/root/c/a/a/examples/connectsock.c:73: undefined reference to `errno'
collect2: ld returned 1 exit status
make: *** [TCPecho] Error 1
代码中有extern int errno
但为甚末找不到呢?
关于这两本书的代码编译似乎许多人都有问题,请高手赐教!
|
Solaris 9 SPARC + gcc 2.95.3
TCP/IP Illustrated, Volume 3的代码编译要修改Makefile的
注意一下README里的这一句:
Then change the definitions of CC, CFLAGS, and LIBS in the Makefile, as appropriate for your system.
TCP/IP Illustrated, Volume 3的代码编译要修改Makefile的
注意一下README里的这一句:
Then change the definitions of CC, CFLAGS, and LIBS in the Makefile, as appropriate for your system.
|
UNIX Network Programming, Volume 1, Second Edition
gunzip -c unpv12e.tar.gz | tar xvf -
cd unpv12e
./configure # try to figure out all implementation differences
cd lib # build the basic library that all programs need
make # use "gmake" everywhere on BSD/OS systems
cd ../libfree # continue building the basic library
make
cd ../libgai # the getaddrinfo() and getnameinfo() functions
make
cd ../libroute # only if your system supports 4.4BSD style routing sockets
make # only if your system supports 4.4BSD style routing sockets
cd ../libxti # only if your system supports XTI
make # only if your system supports XTI
cd ../intro # build and test a basic client program
make daytimetcpcli
./daytimetcpcli 127.0.0.1
If all that works, you're all set to start compiling individual programs.
TCP/IP Illustrated, Volume 3
cc -c error.c sleepus.c
ar -crv libmisc.a error.o sleepus.o
ranlib libmisc.a # needed for a BSD-derived system
Then change the definitions of CC, CFLAGS, and LIBS in the Makefile,
as appropriate for your system. Then you can "make all".
如果不行,你应该检查你的编译环境,这些代码我都编译过的,至于“关于这两本书的代码编译似乎许多人都有问题”是因为许多人都没看README
gunzip -c unpv12e.tar.gz | tar xvf -
cd unpv12e
./configure # try to figure out all implementation differences
cd lib # build the basic library that all programs need
make # use "gmake" everywhere on BSD/OS systems
cd ../libfree # continue building the basic library
make
cd ../libgai # the getaddrinfo() and getnameinfo() functions
make
cd ../libroute # only if your system supports 4.4BSD style routing sockets
make # only if your system supports 4.4BSD style routing sockets
cd ../libxti # only if your system supports XTI
make # only if your system supports XTI
cd ../intro # build and test a basic client program
make daytimetcpcli
./daytimetcpcli 127.0.0.1
If all that works, you're all set to start compiling individual programs.
TCP/IP Illustrated, Volume 3
cc -c error.c sleepus.c
ar -crv libmisc.a error.o sleepus.o
ranlib libmisc.a # needed for a BSD-derived system
Then change the definitions of CC, CFLAGS, and LIBS in the Makefile,
as appropriate for your system. Then you can "make all".
如果不行,你应该检查你的编译环境,这些代码我都编译过的,至于“关于这两本书的代码编译似乎许多人都有问题”是因为许多人都没看README
|
可能是内核升级后,头文件位置更改了。可以检查一下定义errno的头文件是否被正确地include了。
|
extern是声明而不是定义!!!!应该是你少包含了某个定义了errno的文件!
|
你好,我也是unix爱好者,
我编译unix网络编程(第2版)时出现以下错误,请问是怎么回事呀?谢谢!
你的unp.h文件能不能通过编译呀?如果能的话,给我发一份好吗?
bash-2.05$ gcc daytimetcpcli01.c -o daytimetcpcli
In file included from unp.h:13,
from daytimetcpcli01.c:1:
/usr/local/lib/gcc-lib/sparc-sun-solaris2.9/3.3.2/include/sys/types.h:85: error: conflicting t'
/usr/include/sys/int_types.h:69: error: previous declaration of `int32_t'
In file included from unp.h:200,
from daytimetcpcli01.c:1:
addrinfo.h:10: error: redefinition of `struct addrinfo'
In file included from unp.h:200,
from daytimetcpcli01.c:1:
addrinfo.h:22:1: warning: "AI_PASSIVE" redefined
我编译unix网络编程(第2版)时出现以下错误,请问是怎么回事呀?谢谢!
你的unp.h文件能不能通过编译呀?如果能的话,给我发一份好吗?
bash-2.05$ gcc daytimetcpcli01.c -o daytimetcpcli
In file included from unp.h:13,
from daytimetcpcli01.c:1:
/usr/local/lib/gcc-lib/sparc-sun-solaris2.9/3.3.2/include/sys/types.h:85: error: conflicting t'
/usr/include/sys/int_types.h:69: error: previous declaration of `int32_t'
In file included from unp.h:200,
from daytimetcpcli01.c:1:
addrinfo.h:10: error: redefinition of `struct addrinfo'
In file included from unp.h:200,
from daytimetcpcli01.c:1:
addrinfo.h:22:1: warning: "AI_PASSIVE" redefined
|
哈哈,问题解决了
|
你看的unix编程比一定就是linux编程!各个操作系统的头文件还是有点区别的