Warning: Multiple build commands for output file

本文介绍了一种常见的编译警告:“Multiple build commands for output”,并提供了避免资源文件重复引入的方法,包括正确删除和添加资源文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天编译项目;得到一个编译警告:
Warning: Multiple build commands for output /.../...

出现这种 Warning 的原因
由于将原来资源文件包删除,重新加入后,导致编译器在编译时,又一次引入了该资源!也就是说,编译的外部资源引入重复!

解决方法:

如何避免种情况的发生

1.删除项目文件,要从工程中删除。
2.切记,同一个资源不可重复引用到工程中。
3.添加资源,要从工程中添加。
4.最好,再删除资源后,先Clean 一下项目。

vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `aacps_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `aac_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `aac_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `dv_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `dv_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `sinewin_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `sinewin_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `mpegaudio_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `mpegaudio_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `motionpixels_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `motionpixels_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `pcm_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `pcm_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: overriding commands for target `qdm2_tables.h' vendor/amlogic/frameworks/av/LibPlayer/amffmpeg/libavcodec/Makefile:725: warning: ignoring old commands for target `qdm2_tables.h' build/core/Makefile:34: warning: overriding commands for target `out/target/product/p201/system/lib/hw/audio.huitong.default.so' build/core/base_rules.mk:319: warning: ignoring old commands for target `out/target/product/p201/system/lib/hw/audio.huitong.default.so' build/core/Makefile:34: warning: overriding commands for target `out/target/product/p201/system/bin/remotecfg' build/core/base_rules.mk:319: warning: ignoring old commands for target `out/target/product/p201/system/bin/remotecfg' build/core/Makefile:34: warning: overriding commands for target `out/target/product/p201/system/usr/keylayout/Generic.kl' build/core/Makefile:34: warning: ignoring old commands for target `out/target/product/p201/system/usr/keylayout/Generic.kl' build/core/Makefile:34: warning: overriding commands for target `out/target/product/p201/system/lib/libfbaudio.so' build/core/base_rules.mk:319: warning: ignoring old commands for target `out/target/product/p201/system/lib/libfbaudio.so' Starting build with ninja ninja: Entering directory `.' ninja: error: 'art/runtime/interpreter/mterp/out/mterp_x86_64.S', needed by 'out/host/linux-x86/obj/SHARED_LIBRARIES/libart_intermediates/interpreter/mterp/out/mterp_x86_64.o', missing and no known rule to make it build/core/ninja.mk:148: recipe for target 'ninja_wrapper' failed make: *** [ninja_wrapper] Error 1 #### make failed to build some targets (40 seconds) ####怎么解决
06-18
<think>我们正在处理Android或Amlogic项目中的构建问题,具体是Makefile构建过程中出现的两个错误:1.'overridingcommandsfortarget'警告2.'ninja:error:missingandnoknownruletomakeit'错误,涉及目标`libavcodec`和`mterp_x86_64.S`首先,我们分析这两个问题:一、'overridingcommandsfortarget'警告这个警告通常发生在Makefile中,当你多次为同一个目标定义了不同的命令(recipe)时。例如:target:dependencycommand1target:dependencycommand2Makefile不允许为同一个目标定义多个命令块,因为这样会覆盖之前的命令。通常,我们需要将命令合并到一个规则中,或者使用不同的目标。二、'ninja:error:missingandnoknownruletomakeit'错误这个错误表示ninja构建系统找不到生成指定目标文件(例如`libavcodec`或`mterp_x86_64.S`)的规则。可能的原因包括:1.源文件不存在(拼写错误或路径错误)。2.构建规则(在Makefile或Android.mk等文件中)没有正确定义。3.依赖项缺失或路径问题。针对这两个问题,我们逐步解决:###解决步骤####1.解决'overridingcommandsfortarget'警告-在项目目录中搜索警告信息中提到的目标(target)名称。例如,如果警告是`Makefile:10:warning:overridingcommandsfortarget'xxx'`,则去查看该Makefile的第10行。-检查整个Makefile(或相关的.mk文件)中是否多次定义了同一个目标。如果是,需要将命令合并到一个规则中,或者删除多余的定义。-另一种常见情况是多个文件定义了同一个目标。例如,在不同的.mk文件中定义了同一个目标。这时需要检查整个构建系统,确保每个目标只在一个地方定义命令。####2.解决'ninja:error:missingandnoknownruletomakeit'错误-首先,确认错误中提到的文件(如`libavcodec`或`mterp_x86_64.S`)是否存在于源代码目录中。注意,`libavcodec`可能是一个库(通常是一个目录或一组文件),而`mterp_x86_64.S`是一个汇编源文件。-如果文件确实存在,检查构建规则是否正确定义。例如,对于`mterp_x86_64.S`,应该有一个规则将其编译为目标文件(.o)。在Makefile中可能类似于:$(OUT_DIR)/mterp_x86_64.o:path/to/mterp_x86_64.S$(CC)-c$<-o$@-如果文件不存在,需要确认是否应该由某个生成步骤产生(例如,通过工具生成该文件),并且生成规则是否缺失。-另外,检查路径是否正确。在大型项目中,文件可能位于不同的子目录中,而构建规则中可能需要指定相对路径或绝对路径。具体到`libavcodec`和`mterp_x86_64.S`:-**libavcodec**:这通常是FFmpeg的一部分。在Android项目中,可能需要通过配置FFmpeg来构建。检查是否在项目配置中启用了FFmpeg,或者是否正确地包含了FFmpeg的源代码。同时,检查Android.mk(或类似的构建脚本)中是否有定义构建libavcodec的模块。-**mterp_x86_64.S**:这个文件是AndroidART虚拟机的一部分。它应该位于`art/runtime/mterp/x86_64/mterp_x86_64.S`。检查该文件是否存在。如果不存在,可能是源代码下载不完整;如果存在,检查构建脚本中是否包含了对该文件的编译规则。此外,由于错误信息提到ninja,我们可以尝试使用make命令(如果项目支持)来获取更详细的错误信息,因为make有时会提供更友好的输出。例如:make-j1#单线程构建,便于观察错误如果项目使用Android的构建系统(如AOSP),可以尝试:mmmpath/to/module#单独构建出问题的模块或者,使用`mma`命令在模块目录下构建。另外,检查是否有任何构建配置(如环境变量、产品配置)影响了这些模块的构建。例如,产品配置中可能禁用了某些架构(如x86_64),导致mterp_x86_64.S不会被构建。###参考站内引用根据之前提供的引用[^1](尽管是关于内核驱动开发的),我们可以借鉴一些通用方法:-检查依赖:确保所有需要的符号(在这里是文件)都存在,并且构建规则正确定义。-检查配置:确保在构建配置(如Makefile、Android.mk、Android.bp)中没有遗漏。总结步骤:1.搜索整个项目,找到多次定义的目标,合并或删除重复定义。2.确认缺失的文件是否存在,如果不存在,需要生成或从源码中找回。3.检查构建规则,确保正确定义了如何从源文件构建目标。4.检查模块依赖,确保依赖的模块已经正确构建。如果问题仍然存在,可以提供具体的错误输出(包括文件名和行号),以便更精确地定位问题。下面我们生成相关问题:</think>### 解决Makefile构建中的警告和错误 #### 1. **'overriding commands for target'警告** **原因**:当多个Makefile规则尝试为**同一个目标**定义不同的构建命令时,会触发此警告。常见于: - 重复定义同一目标(如多次指定`obj-y += libavcodec`) - 子模块与父Makefile规则冲突 - 条件编译分支中重复添加相同目标 **解决步骤**: 1. **定位冲突目标** 根据警告信息找到目标名(如`libavcodec`)和涉及的Makefile路径: ```makefile # 示例:kernel/drivers/media/Makefile obj-y += libavcodec/ # 首次定义 ... # 另一个文件重复定义 obj-$(CONFIG_AML_MEDIA_CODEC) += libavcodec/ # 触发警告 ``` 2. **合并或删除重复规则** - 保留**一个**权威定义(通常选择父级Makefile) - 注释/删除其他重复条目 ```diff - obj-y += libavcodec/ + # obj-y += libavcodec/ # 已由../media/Makefile定义 ``` 3. **使用中间变量**(复杂项目推荐) ```makefile # 在顶层Makefile定义全局变量 AML_CODEC_MODULES := libavcodec libavformat # 子模块中引用 obj-y += $(AML_CODEC_MODULES)/ ``` #### 2. **'ninja: error: missing and no known rule to make it'错误** **原因**:Ninja找不到构建目标所需的源文件或依赖项,常见于: - 文件路径错误(如`mterp_x86_64.S`路径变更) - 依赖未声明(如头文件未在`LOCAL_SRC_FILES`列出) - 工具链配置错误(交叉编译路径缺失) **解决步骤**: 1. **验证文件存在性** 检查错误中提到的文件(如`mterp_x86_64.S`): ```bash # 在项目根目录执行 find . -name mterp_x86_64.S # 若路径变更,更新Android.mk: LOCAL_SRC_FILES := art/runtime/mterp/x86_64/mterp_x86_64.S ``` 2. **修复依赖链** 在`Android.bp`或`Android.mk`中显式声明依赖: ```makefile # Android.bp示例 cc_library_shared { name: "libart", srcs: ["art/runtime/mterp/x86_64/mterp_x86_64.S"], dependencies: ["libdexfile"], # 添加缺失依赖 } ``` 3. **检查工具链配置** 确保交叉编译工具路径正确(Amlogic项目常见问题): ```makefile # 在envsetup.sh或buildspec.mk中 export CROSS_COMPILE=aarch64-linux-android- export ARCH=arm64 ``` 4. **清理增量构建** Ninja缓存可能导致路径失效: ```bash make clean # 或 ninja -t clean rm -rf out/target/product/<device>/obj/ART/ ``` #### 3. **libavcodec/mterp_x86_64.S专项处理 **libavcodec问题**: 1. 确认FFmpeg配置: ```bash ./configure --enable-shared --disable-static --enable-cross-compile --target-os=android ``` 2. 检查`config.mak`中: ```makefile HAVE_X86ASM=yes # 确保x86汇编启用 ``` **mterp_x86_64.S问题**: 1. 在`art/build/Android.common_build.mk`中添加: ```makefile LOCAL_ASFLAGS += -I$(LOCAL_PATH)/runtime/mterp/x86_64 ``` 2. 对于NASM语法文件: ```makefile LOCAL_MODULE := mterp_x86_64 LOCAL_SRC_FILES := mterp_x86_64.S LOCAL_ASFLAGS := -f elf64 # 指定汇编格式 ``` ### 预防措施 1. **统一规则定义**:使用`include $(CLEAR_VARS)`隔离模块定义 2. **路径检查脚本**: ```bash # 在构建前验证关键文件 check_file() { [ -f "$1" ] || { echo "Missing $1"; exit 1; } } check_file art/runtime/mterp/x86_64/mterp_x86_64.S ``` 3. **Ninja调试**: ```bash ninja -d explain # 显示依赖解析过程 ``` > **关键点**:Android构建系统(Soong/Bp)会转换Makefile规则,确保`Android.bp`和遗留`Android.mk`无冲突定义[^1]。 --- ### 相关问题 1. 如何在Android项目中混合使用`Android.mk`和`Android.bp`而不引发冲突? 2. 当交叉编译Amlogic平台时,如何正确配置工具链路径以避免`no known rule`错误? 3. 有哪些工具可以分析Makefile的重复规则依赖关系? 4. 如何为汇编文件(`.S`)编写跨平台的Android构建规则? [^1]: 参考Android开源项目构建系统文档:https://source.android.com/docs/setup/build
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值