#编译问题# 01 | error: use of undeclared identifier ‘nftw‘

Posted 井方哥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#编译问题# 01 | error: use of undeclared identifier ‘nftw‘相关的知识,希望对你有一定的参考价值。

一、问题

编译时出现如下错误:

FAILED: /Users/xxx/env/android-ndk-r20b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/xxx/env/android-ndk-r20b/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/xxx/env/android-ndk-r20b/toolchains/llvm/prebuilt/darwin-x86_64/sysroot  -DEnableLOG -DQUT_STATISTIC_ENABLE -I../../../../src/main/cpp/external/libunwindstack/deps/android-base -I../../../../src/main/cpp/external/libunwindstack/deps/android-base/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security   -Oz -DNDEBUG  -fPIC   -Wall -Wextra -Wexit-time-destructors -MD -MT src/main/cpp/external/libunwindstack/deps/android-base/CMakeFiles/android-base.dir/file.cpp.o -MF src/main/cpp/external/libunwindstack/deps/android-base/CMakeFiles/android-base.dir/file.cpp.o.d -o src/main/cpp/external/libunwindstack/deps/android-base/CMakeFiles/android-base.dir/file.cpp.o -c /Users/xxx/src/main/cpp/external/libunwindstack/deps/android-base/file.cpp
  /Users/xxx/src/main/cpp/external/libunwindstack/deps/android-base/file.cpp:165:3: error: use of undeclared identifier 'nftw'
    nftw(path, callback, 128, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
    ^
  1 error generated.

定位原代码

 nftw(path, callback, 128, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);

二、分析

发现:nftw这个函数具体如下

#if __ANDROID_API__ >= 17
int ftw(const char* __dir_path, int (*__callback)(const char*, const struct stat*, int), int __max_fd_count) __INTRODUCED_IN(17);
int nftw(const char* __dir_path, int (*__callback)(const char*, const struct stat*, int, struct FTW*), int __max_fd_count, int __flags) __INTRODUCED_IN(17);
int ftw64(const char* __dir_path, int (*__callback)(const char*, const struct stat64*, int), int __max_fd_count) __RENAME_STAT64(ftw, 17, 21);
int nftw64(const char* __dir_path, int (*__callback)(const char*, const struct stat64*, int, struct FTW*), int __max_fd_count, int __flags) __RENAME_STAT64(nftw, 17, 21);
#endif /* __ANDROID_API__ >= 17 */

原来,仅 Android API >=17 时 才支持这个函数

三、问题修复

修改方案就是修改Android的minSdkVersion,如上 要>=17

android
    compileSdkVersion 29
    defaultConfig 
        minSdkVersion 17 // 修改的值要大于要求的版本
        targetSdkVersion 29
        versionCode 1
        versionName "1.0.0"

以上是关于#编译问题# 01 | error: use of undeclared identifier ‘nftw‘的主要内容,如果未能解决你的问题,请参考以下文章

#编译问题# 01 | error: use of undeclared identifier ‘nftw‘

MATLAB-matconvnet报错:Error using mex ...... error: ‘numeric_limits’ is not a member of ‘std’

error C2275: 'SOCKET' : illegal use of this type as an expression

三个方法解决error: use of moved value

RedShift Error when using COUNT (Distinct XXX) ERROR: XX000: This type of associated subquery patter

swig c++ to python (with numpy): error: use of undeclared identifier 'import_array'