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

已安装OpenJDK 21仍提示缺失开发包,perf编译报错如何解决?

编译perf工具遇到的JDK检测失败与C90编译错误解决方法

问题现象

1. JDK检测异常

已通过预构建版本安装并链接OpenJDK 21,但执行make -C tools/perf/编译perf工具时,仍提示JDK开发包未找到:

Makefile.config:1105: No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel

本地Java环境版本信息:

pegasus@pegasus:~/Documents/perf-6.4.0$ java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-58)
OpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)
pegasus@pegasus:~/Documents/perf-6.4.0$ javac --version
javac 21.0.2

2. C90语法编译错误

编译过程中触发ISO C90语法限制报错,且警告被强制转为错误:

error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

完整编译日志:

pegasus@pegasus:~/Documents/perf-6.4.0$ make -C tools/perf/
make: Entering directory '/home/pegasus/Documents/perf-6.4.0/tools/perf'
  BUILD:   Doing 'make -j16' parallel build
Makefile.config:1105: No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel

  INSTALL libsubcmd_headers
  INSTALL libapi_headers
  INSTALL libperf_headers
  INSTALL libsymbol_headers
  GEN     python/perf.cpython-312-x86_64-linux-gnu.so
  INSTALL libbpf_headers
  CC      scripts/python/Perf-Trace-Util/Context.o
In file included from /home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/Python.h:44,
                 from scripts/python/Perf-Trace-Util/Context.c:14:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/object.h: In function ‘Py_SIZE’:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/object.h:233:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  233 |     PyVarObject *var_ob = _PyVarObject_CAST(ob);
      |     ^~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/Python.h:53:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/cpython/longintrepr.h:121:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  121 |     Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
      |     ^~~~~~~~~~
  CC      util/scripting-engines/trace-event-python.o
In file included from /home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/Python.h:44,
                 from util/scripting-engines/trace-event-python.c:22:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/object.h: In function ‘Py_SIZE’:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/object.h:233:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  233 |     PyVarObject *var_ob = _PyVarObject_CAST(ob);
      |     ^~~~~~~~~~~
cc1: all warnings being treated as errors
In file included from /home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/Python.h:53:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’:
/home/linuxbrew/.linuxbrew/opt/python@3.12/include/python3.12/cpython/longintrepr.h:121:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  121 |     Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
      |     ^~~~~~~~~~
make[5]: *** [/home/pegasus/Documents/perf-6.4.0/tools/build/Makefile.build:98: scripts/python/Perf-Trace-Util/Context.o] Error 1
make[4]: *** [/home/pegasus/Documents/perf-6.4.0/tools/build/Makefile.build:140: python/Perf-Trace-Util] Error 2
make[3]: *** [/home/pegasus/Documents/perf-6.4.0/tools/build/Makefile.build:140: scripts] Error 2
make[3]: *** Waiting for unfinished jobs....
^Cmake[5]: *** [/home/pegasus/Documents/perf-6.4.0/tools/build/Makefile.build:98: util/scripting-engines/trace-event-python.o] Interrupt
make[4]: *** [/home/pegasus/Documents/perf-6.4.0/tools/build/Makefile.build:140: scripting-engines] Interrupt
interrupted
make[3]: *** [/home/pegasus/Documents/perf-6.4.0/tools/build/Makefile.build:140: util] Interrupt
make[2]: *** [Makefile.perf:675: perf-in.o] Interrupt
make[2]: *** [Makefile.perf:650: python/perf.cpython-312-x86_64-linux-gnu.so] Interrupt
make[1]: *** [Makefile.perf:235: sub-make] Interrupt
make: *** [Makefile:70: all] Interrupt

原因分析

1. JDK检测失败

perf的Makefile脚本仅适配旧版本JDK的命名规则(如openjdk-8-jdk),未兼容OpenJDK 21的路径结构;同时预构建版本的JDK头文件、库文件路径不在脚本默认搜索范围内,导致检测逻辑失效。

2. C90编译错误

perf编译默认启用-Werror=declaration-after-statement参数,将C99及以后的“代码块中间声明变量”语法视为错误;而Python 3.12的头文件采用了该语法,违反C90标准触发报错。

解决方法

一、修复JDK检测问题

方法1:编译时指定JDK路径

直接向Makefile传递JDK安装路径:

# 替换为你的OpenJDK 21实际路径,例如linuxbrew安装路径为/home/linuxbrew/.linuxbrew/opt/openjdk@21
make -C tools/perf/ JAVA_HOME=/path/to/your/openjdk21

方法2:创建软链接适配检测逻辑

针对脚本的旧版本路径识别逻辑,创建软链接让脚本找到JDK:

sudo ln -s /path/to/your/openjdk21/include /usr/include/java-openjdk-21
sudo ln -s /path/to/your/openjdk21/lib /usr/lib/java-openjdk-21

二、修复C90编译错误

方法1:编译时关闭错误警告

添加CFLAGS参数禁用该强制错误:

make -C tools/perf/ CFLAGS="-Wno-declaration-after-statement"

方法2:修改Makefile配置

打开tools/perf/Makefile.config,找到包含-Werror=declaration-after-statement的行,注释或删除该参数后重新编译。

三、组合解决两个问题

同时指定JDK路径并关闭错误警告:

make -C tools/perf/ JAVA_HOME=/path/to/your/openjdk21 CFLAGS="-Wno-declaration-after-statement"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 03:00:00