解决Android 源码编译“audio_processing_impl”时,报错“fatal error: list: No such file or directory”问题

我的系统是Linux Mint 17,使用的平台是Tiny4412,编译的是友善之臂提供的Android 4.2.2 源码。之前编译没有问题,今天编译时,报出这个错误,查遍 百度/Google 都没解决,后来发现是我之前手贱多配置了一个环境变量 NDK_ROOT 导致的问题,报错如下:

target arm C++: libwebrtc_apm <= external/webrtc/src/modules/audio_processing/audio_processing_impl.cc
In file included from external/webrtc/src/modules/audio_processing/audio_processing_impl.cc:11:0:
external/webrtc/src/modules/audio_processing/audio_processing_impl.h:16:16: fatal error: list: No such file or directory
compilation terminated.
make: *** [out/target/product/tiny4412/obj/STATIC_LIBRARIES/libwebrtc_apm_intermediates/audio_processing_impl.o] Error 1

分析过程如下:

查的两个地址:

http://grokbase.com/t/gg/android-building/1336gfcert/building-android-4-2-1-problems-with-stl-reference-in-source-tree

http://bbs.csdn.net/topics/390143470

看后无果,只知道是没找到头文件“list”,在工程目录下使用

find ./ -name "list"
找到了包括“./external/stlport/stlport/list”等多个文件,说明文件是有的,就是没链接上。


于是,跑去

external/webrtc/src/modules/audio_processing/Android.mk
看看是怎么回事,Android.mk内容如下(省略部分无关信息):

#省略。。。
LOCAL_SRC_FILES := \
    $(call all-proto-files-under, .) \
    audio_buffer.cc \
    audio_processing_impl.cc \
    echo_cancellation_impl.cc \
    echo_control_mobile_impl.cc \
    gain_control_impl.cc \
    high_pass_filter_impl.cc \
    level_estimator_impl.cc \
    noise_suppression_impl.cc \
    splitting_filter.cc \
    processing_component.cc \
    voice_detection_impl.cc
#省略。。。
ifndef NDK_ROOT
include external/stlport/libstlport.mk
endif
#省略。。。
ifdef NDK_ROOT
include $(BUILD_EXECUTABLE)
else
include external/stlport/libstlport.mk
include $(BUILD_NATIVE_TEST)
endif
#省略。。。
ifdef NDK_ROOT
include $(BUILD_EXECUTABLE)
else
include external/stlport/libstlport.mk
include $(BUILD_NATIVE_TEST)
endif

猛然发现,这里有多处
ifdef NDK_ROOT
且看最后一个ifdef中

ifdef NDK_ROOT
include $(BUILD_EXECUTABLE)
else
include external/stlport/libstlport.mk
include $(BUILD_NATIVE_TEST)
endif

如果没有定义

NDK_ROOT
则会包含
external/stlport/libstlport.mk
慢着!怎么这么眼熟,stlport?这不是刚刚搜索结果中的一个吗?马上查看libstlport.mk,看看里面都是什么?

# Add a couple include paths to use stlport.

# Make sure bionic is first so we can include system headers.
LOCAL_C_INCLUDES := \
	bionic \
	external/stlport/stlport \
	$(LOCAL_C_INCLUDES)

“external/stlport/stlport”!!!还有“bionic”!!!这两条都在前面提到的地址中提到

http://grokbase.com/t/gg/android-building/1336gfcert/building-android-4-2-1-problems-with-stl-reference-in-source-tree

原文如下:

I posted this same question into the forum earlier, but it has not
appeared. Apologies if this does end up appearing twice.

When building Android 4.2.1 I'm getting the following error...

target arm C++: libwebrtc_apm <=
external/webrtc/src/modules/audio_processing/audio_processing_impl.cc
In file included from
external/webrtc/src/modules/audio_processing/audio_processing_impl.cc:11:0:
external/webrtc/src/modules/audio_processing/audio_processing_impl.h:16:16:
fatal error: list: No such file or directory
compilation terminated.

This is referring to the following line in audio_processing_impl.cc...

#include <list>


In other words, it appears to not know about STL.

I ran the build using the same source tree on a colleague's PC (which
builds without error), and compared the builds when using showcommands. On
my colleague's PC there was one difference in the build command for
audio_processing_impl.cc - the inclusion in his case of the following...

-I bionic -I external/stlport/stlport -I


... Which explains why this is going wrong. Without this line, on my PC
the build does not have the necessary STL references.

I've looked at the various packages installed on both machines, and they
appear the same - and in any case, I was under the impression the toolchain
was integrated in the Android source tree,

One other difference which may well be the cause of the problem is that my
PC runs Ubuntu 12.10, whilst my colleague's PC is running 12.04. I'm know
that 12.10 may cause issues - and this may be one of them - but does the
above ring any bells with anyone out there? What could cause the Android
build to omit that reference to the STL code?

Any help much appreciated!
Tim

也就是说,我并没有包含到 libstlport.mk ,进而说明,我定义了NDK_ROOT,后来一查:

$ echo $NDK_ROOT
/opt/android-ndk-r10
果然如此!所以,我临时解除了NDK_ROOT变量

$ unset NDK_ROOT
然后,

make
就通过了!!! 大哭 大哭 大哭

真是手贱害死人啊~
只要这一轮正常编译,不使用make clean清空就不需要管NDK_ROOT环境变量了,你重设也好,重启系统也罢,下次遇到这个问题,若你定义了NDK_ROOT,unset一下试试吧。


参考文献:

1. http://grokbase.com/t/gg/android-building/1336gfcert/building-android-4-2-1-problems-with-stl-reference-in-source-tree     [android-building] Building Android 4.2.1... problems with STL reference in source tree

2. http://bbs.csdn.net/topics/390143470     编译Android源码出错!!!

3. http://zhidao.baidu.com/link?url=lZhd8cm9cR05WwCCu22Vgkq_W2K91gefD0ncet5xp-8tHNKic1Ls-UhgjdmDINmATkFjJdneVYv4pr4aDtsMQ_   百度知道-原生的Android代码上创建自己的product,编译出错!!!

4. http://qnalist.com/questions/5099386/android-building-android-4-2-1-build-problems-c-stl-issue-with-external-webrtc-src-modules-audi       [android-building] Android 4.2.1 Build Problems: C++ STL Issue With External/webrtc/src/modules/audi



<think>我们被要求解决一个编译错误:`esp_timer.h: No such file or directory`。根据引用[3]中提到的类似错误(esp_bt.h缺失)以及引用[2]中使用了`esp_timer.h`的示例代码,我们可以推断这个错误通常是由于缺少必要的组件配置或路径设置问题引起的。 步骤分析: 1. 检查头文件是否存在:`esp_timer.h`是ESP-IDF中定器组件的头文件,通常位于`components/esp_timer/include`目录下。如果项目中没有正确包含这个路径,就会报错。 2. 检查项目配置:在ESP-IDF项目中,我们需要确保正确配置了组件依赖。特别是,如果使用了定器功能,需要确保在`menuconfig`中启用了相关选项(但通常`esp_timer`是默认启用的)。 3. 检查CMakeLists.txt:在组件的CMakeLists.txt文件中,需要添加对`esp_timer`组件的依赖。 根据引用[2]中的代码示例,我们使用了`esp_timer.h`,因此需要确保在组件的CMakeLists.txt中添加了`REQUIRES esp_timer`或者`PRIV_REQUIRES esp_timer`。 解决方案: 1. 确认你的项目是基于ESP-IDF框架,并且已经正确安装了ESP-IDF环境(包括设置IDF_PATH环境变量)。 2. 检查你的组件(通常是main组件)的CMakeLists.txt文件,确保添加了对`esp_timer`的依赖。例如: ```cmake idf_component_register(SRCS "your_source_file.c" INCLUDE_DIRS "include" REQUIRES esp_timer) ``` 如果这个组件不需要对外暴露头文件,也可以使用`PRIV_REQUIRES`。 3. 如果项目中没有使用组件结构,而是在主CMakeLists.txt中直接编译,那么确保在顶层CMakeLists.txt中添加了`esp_timer`组件依赖: ```cmake set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/components/esp_timer) ``` 或者使用`target_link_libraries`(在较新的ESP-IDF版本中,通常使用组件依赖的方式)。 4. 清理并重新编译项目:有候需要清理构建目录并重新编译。 ``` idf.py fullclean idf.py build ``` 如果以上步骤还不能解决问题,请检查你的ESP-IDF版本是否过旧,因为`esp_timer`组件在较新的版本中可能会有变动。可以尝试更新ESP-IDF到最新版本。 相关问题: 1. 如何配置ESP-IDF项目的CMakeLists.txt? 2. 如何解决ESP32开发中的其他常见头文件缺失问题? 3. 如何更新ESP-IDF到最新版本?</think>### 解决ESP32编译错误 `esp_timer.h: No such file or directory` #### 问题原因分析 该错误通常由以下原因导致: 1. **组件依赖缺失**:项目未正确声明对`esp_timer`组件的依赖[^1]。 2. **IDF版本不兼容**:旧版ESP-IDF(<4.0)需手动启用`CONFIG_ESP_TIMER_IMPL`配置[^2]。 3. **路径配置错误**:编译系统未正确包含`esp_timer`组件的头文件路径。 #### 解决方案 ##### 步骤1:添加组件依赖 在组件的 **CMakeLists.txt** 中添加依赖声明: ```cmake idf_component_register( SRCS "main.c" INCLUDE_DIRS "." REQUIRES esp_timer # 关键依赖声明 ) ``` ##### 步骤2:检查SDK配置(仅旧版IDF) 若使用ESP-IDF v3.x,在 `sdkconfig` 文件中添加: ```ini CONFIG_ESP_TIMER_IMPL=y ``` ##### 步骤3:验证头文件路径 确保头文件包含路径正确: ```c #include "esp_timer.h" // 正确写法(无路径前缀) ``` ##### 步骤4:清理并重新编译 ```bash idf.py fullclean # 清理构建缓存 idf.py build # 重新编译 ``` #### 补充说明 1. **ESP-IDF版本要求**:`esp_timer` 在ESP-IDF v4.0+ 默认可用,建议升级至最新稳定版[^1]。 2. **依赖传递**:若通过其他组件(如`esp_http_client`)间接使用定器,仍需显式声明`REQUIRES esp_timer`[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值