laub 发表于 2005-03-05 15:25

W.Richard Stevens 的源码编译报错,肯定是我的问题,请帮我!

W.Richard Stevens 的源码编译报错,肯定是我的问题,请帮我!

下载了unp1的源码,在redhat中解压缩,按照README,

$ ./configure &

然后
$ cd 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: error: redefinition of `struct in_pktinfo'
make: *** Error 1


编译进行不下去了。说unp.h 第114行 有那个重复的定义。我把114的
struct in_pktinfo &注释掉就编译通过了。

哎,我怎么才能不注释它,又能够通过呢?

我终于买到了unp这本书了,我一定要好好把它学完!

这里一定有很多高手研究过这本书,请指导我,谢谢!

laub 发表于 2005-03-05 16:33

W.Richard Stevens 的源码编译报错,肯定是我的问题,请帮我!

unp.h中,定义为

/* The structure returned by recvfrom_flags() */
struct in_pktinfo {
struct in_addr    ipi_addr;    /* dst IPv4 address */
int      ipi_ifindex;                  /* received interface index */
};


刚刚找了一下,在linux系统include文件中已经定义了这个结构

/usr/include/linux/in.h

struct in_pktinfo
{
      int             ipi_ifindex;
      struct in_addripi_spec_dst;
      struct in_addripi_addr;
};




/usr/include/bits/in.h

/* Structure used for IP_PKTINFO.*/
struct in_pktinfo
{
    int ipi_ifindex;                        /* Interface index*/
    struct in_addr ipi_spec_dst;   /* Routing destination address*/
    struct in_addr ipi_addr;         /* Header destination address*/
};



就是这个原因导致了上面的报错,那么我把unp.h中的结构注释掉了,未来的程序在处理这个结构时,会出错吗?

我该怎么处理这个问题?

laub 发表于 2005-03-05 16:40

W.Richard Stevens 的源码编译报错,肯定是我的问题,请帮我!

又看了半天,如果按结构内的成员的变量名访问,就不会出错。

算是解决了。

waxberry2000 发表于 2005-03-15 20:29

W.Richard Stevens 的源码编译报错,肯定是我的问题,请帮我!

我也碰到这个问题。
应该不会有错,只不过是定义这个结构的地方变了。

lishuai_girl 发表于 2008-05-18 08:24

在书上后面的附录中,unp.h中这个结构似乎是unp_in_pktinfo
页: [1]
查看完整版本: W.Richard Stevens 的源码编译报错,肯定是我的问题,请帮我!