You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04下安装barnyard2编译失败求助

问题描述

我在搭载AMD CPU的Ubuntu 22.04系统中,尝试通过barnyard2将Snort日志同步到MySQL数据库,操作参考某指南,但安装遇到问题。

执行./configure --with-mysql --with-mysql-libraries=/usr/lib/x86_64-linux-gnu无报错,执行make时出现编译错误,错误日志如下:

make  all-recursive
make[1]: Entering directory '/home/faygo/Downloads/barnyard2-2-1.13'
Making all in src
make[2]: Entering directory '/home/faygo/Downloads/barnyard2-2-1.13/src'
Making all in sfutil
make[3]: Entering directory '/home/faygo/Downloads/barnyard2-2-1.13/src/sfutil'
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o getopt_long.o getopt_long.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sfmemcap.o sfmemcap.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sfprimetable.o sfprimetable.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sfxhash.o sfxhash.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sf_ip.o sf_ip.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sf_iph.o sf_iph.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sf_ipvar.o sf_ipvar.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sf_textlog.o sf_textlog.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I..  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o sf_vartable.o sf_vartable.c
rm -f libsfutil.a
ar cru libsfutil.a getopt_long.o sfmemcap.o sfprimetable.o sfxhash.o sf_ip.o sf_iph.o sf_ipvar.o sf_textlog.o sf_vartable.o
ar: `u' modifier ignored since `D' is the default (see `U')
ranlib libsfutil.a
make[3]: Leaving directory '/home/faygo/Downloads/barnyard2-2-1.13/src/sfutil'
Making all in output-plugins
make[3]: Entering directory '/home/faygo/Downloads/barnyard2-2-1.13/src/output-plugins'
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_arubaaction.o spo_alert_arubaaction.c
In file included from /usr/include/string.h:535,
                 from spo_alert_arubaaction.c:64:
In function ‘strncpy’,
    inlined from ‘ParseAlertArubaActionArgs’ at spo_alert_arubaaction.c:592:2:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~
spo_alert_arubaaction.c: In function ‘ParseAlertArubaActionArgs’:
spo_alert_arubaaction.c:592:9: note: length computed here
  592 |         strncpy(data->secret, toks[2], strlen(toks[2]));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/string.h:535,
                 from spo_alert_arubaaction.c:64:
In function ‘strncpy’,
    inlined from ‘ParseAlertArubaActionArgs’ at spo_alert_arubaaction.c:621:3:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~
spo_alert_arubaaction.c: In function ‘ParseAlertArubaActionArgs’:
spo_alert_arubaaction.c:621:17: note: length computed here
  621 |                 strncpy(data->role_name, action_toks[1],
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  622 |                                 strlen(action_toks[1]));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_bro.o spo_alert_bro.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_cef.o spo_alert_cef.c
spo_alert_cef.c: In function ‘AlertCEF’:
spo_alert_cef.c:500:42: warning: variable ‘cn’ set but not used [-Wunused-but-set-variable]
  500 |         ClassType                       *cn;
      |                                          ^~
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_csv.o spo_alert_csv.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_fast.o spo_alert_fast.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_full.o spo_alert_full.c
gcc -DHAVE_CONFIG_H -I. -I../.. -I.. -I ../sfutil  -I/usr/include//mysql -DENABLE_MYSQL  -g -O2 -Wall -c -o spo_alert_fwsam.o spo_alert_fwsam.c
In file included from /usr/include/pcap/pcap.h:130,
                 from /usr/include/pcap.h:43,
                 from ../barnyard2.h:46,
                 from spo_alert_fwsam.c:91:
spo_alert_fwsam.c:118:13: error: two or more data types in declaration specifiers
  118 | typedef int SOCKET;
      |             ^~~~~~
spo_alert_fwsam.c:118:1: warning: useless type name in empty declaration
  118 | typedef int SOCKET;
      | ^~~~~~~
spo_alert_fwsam.c: In function ‘FWsamReadLine’:
spo_alert_fwsam.c:620:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  620 |         if(p>buf);
      |         ^~
spo_alert_fwsam.c:621:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
  621 |             strcpy(buf,p);
      |             ^~~~~~
spo_alert_fwsam.c: In function ‘AlertFWsam’:
spo_alert_fwsam.c:979:18: warning: variable ‘cn’ set but not used [-Wunused-but-set-variable]
  979 |     ClassType   *cn = NULL;
      |                  ^~
spo_alert_fwsam.c:978:18: warning: variable ‘sn’ set but not used [-Wunused-but-set-variable]
  978 |     SigNode     *sn = NULL;
      |                  ^~
spo_alert_fwsam.c:971:27: warning: variable ‘lastbsp’ set but not used [-Wunused-but-set-variable]
  971 |     static unsigned short lastbsp[FWSAM_REPET_BLOCKS];
      |                           ^~~~~~~
make[3]: *** [Makefile:391: spo_alert_fwsam.o] Error 1
make[3]: Leaving directory '/home/faygo/Downloads/barnyard2-2-1.13/src/output-plugins'
make[2]: *** [Makefile:497: all-recursive] Error 1
make[2]: Leaving directory '/home/faygo/Downloads/barnyard2-2-1.13/src'
make[1]: *** [Makefile:416: all-recursive] Error 1
make[1]: Leaving directory '/home/faygo/Downloads/barnyard2-2-1.13'
make: *** [Makefile:348: all] Error 2
问题排查与解决

核心错误是spo_alert_fwsam.c:118:13: error: two or more data types in declaration specifiers,原因是**SOCKET类型已经被系统头文件(比如pcap.h依赖的头文件)定义过**,而barnyard2的代码里又重复typedef了一次。

解决步骤:

  1. 打开src/output-plugins/spo_alert_fwsam.c文件
  2. 找到第118行的typedef int SOCKET;,将其替换为条件编译,避免重复定义:
#ifndef SOCKET
typedef int SOCKET;
#endif

或者直接注释掉这一行(如果确认系统已经定义了SOCKET类型)。
3. 保存文件后,重新执行make命令。

额外说明:

  • 其他警告(比如strncpy截断、未使用变量)不影响编译,可以忽略,或者后续需要时再修复。
  • 如果还有其他报错,检查是否缺少依赖包,确保安装完整:
sudo apt install libpcap-dev libmysqlclient-dev build-essential

内容的提问来源于stack exchange,提问作者Daniel Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 22:37:11