在 linux 上编译 isc-dhcp-server

Compile isc-dhcp-server on linux

我想从这个存储库的源代码编译和调试 DHCP 服务器: https://github.com/isc-projects/dhcp

我所做的一切:

./configure

make

但是我这两条命令错误很多

/usr/bin/ld: dhcpd-mdb.o:/home/ali/programming/c/opensource/dhcp/server/mdb.c:70: multiple definition of `dhcp_type_host'; dhcpd-omapi.o:/home/ali/programming/c/opensource/dhcp/server/omapi.c:50: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:529: dhcpd] Error 1
make[2]: Leaving directory '/home/ali/programming/c/opensource/dhcp/server'
make[1]: *** [Makefile:970: all-recursive] Error 1
make[1]: Leaving directory '/home/ali/programming/c/opensource/dhcp/server'
make: *** [Makefile:496: all-recursive] Error 1

但是为什么呢?如何编译 isc-dhcp-server ?

我的 linux 发行版是 debian v11。

更新:

在编译 isc-dhcp 之前,我安装了它的要求。

# apt install bind9-dev

然后我 运行 这个命令而不是 make :

make -C server install

但是出现这个错误:

make: Entering directory '/home/ali/programming/c/opensource/dhcp/server'
Making install in .
make[1]: Entering directory '/home/ali/programming/c/opensource/dhcp/server'
gcc -DHAVE_CONFIG_H -I. -I../includes  -I.. -DLOCALSTATEDIR='"/var"'   -g -O2  -Wall -Werror -fno-strict-aliasing -I../includes -I/home/ali/programming/c/opensource/dhcp/bind/include -MT dhcpd-mdb6.o -MD -MP -MF .deps/dhcpd-mdb6.Tpo -c -o dhcpd-mdb6.o `test -f 'mdb6.c' || echo './'`mdb6.c
mdb6.c: In function ‘create_prefix6’:
mdb6.c:1948:3: error: writing 16 bytes into a region of size 1 [-Werror=stringop-overflow=]
 1948 |   memcpy(new_ds.buffer->data + ds.len, &tmp, sizeof(tmp));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../includes/dhcpd.h:97,
                 from mdb6.c:175:
../includes/tree.h:62:16: note: at offset 0 to object ‘data’ with size 1 declared here
   62 |  unsigned char data [1];
      |                ^~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:738: dhcpd-mdb6.o] Error 1
make[1]: Leaving directory '/home/ali/programming/c/opensource/dhcp/server'
make: *** [Makefile:921: install-recursive] Error 1
make: Leaving directory '/home/ali/programming/c/opensource/dhcp/server'

这是我的配置输出结果:

     ISC DHCP source configure results:
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Package:
  Name:          DHCP
  Version:       4.4.2b1

C Compiler:      gcc

Flags:
  DEFS:          -DHAVE_CONFIG_H
  CFLAGS:        -g -O2  -Wall -Werror -fno-strict-aliasing -I$(top_srcdir)/includes -I/home/ali/programming/c/opensource/dhcp/bind/include

DHCP versions:   DHCPv4 and DHCPv6

Features:
  debug:         no
  failover:      yes
  execute:       yes
  binary-leases: no
  dhcpv6:        yes
  delayed-ack:   yes
  dhcpv4o6:      no
  relay-port:    no

Developer:
  ATF unittests : no


Now you can type make to build ISC DHCP

解决方案

我们应该从 here

克隆 isc-dhcp 服务

您似乎正在编译旧仓库的最后一次提交。 github 页面指向 isc's gitlab site 的较新提交的较新回购。

您也可以切换到最新的稳定标签git checkout v4_4_2_p1以获得更好的稳定性。

请注意,我能够使用 gcc-9 构建它,对我来说最新的稳定标签不会使用 gcc-10 构建,这是 debian 11 的软件包版本。这是一个 open issue