Я работаю над проектом, который использует NDK для чтения в файлах (через filedescriptor). Проект построен с использованием cmake.
Я пытаюсь работать с ним, но независимо от того, что я делаю, любая ссылка на fdsan завершается ошибкой с
use of undeclared identifier 'android_fdsan_<x>
:
Error while executing process /Users/tim/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/tim/Projects/Android/Shuttle2/taglib/lib/.cxx/cmake/debug/arm64-v8a artwork-provider file-scanner}
ninja: Entering directory `/Users/tim/Projects/Android/Shuttle2/taglib/lib/.cxx/cmake/debug/arm64-v8a'
[1/4] Building CXX object CMakeFiles/file-scanner.dir/FileScanner.cpp.o
FAILED: CMakeFiles/file-scanner.dir/FileScanner.cpp.o
/Users/tim/Library/Android/sdk/ndk/21.0.6011959/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/tim/Library/Android/sdk/ndk/21.0.6011959/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/tim/Library/Android/sdk/ndk/21.0.6011959/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -Dfile_scanner_EXPORTS -I/Users/tim/Projects/Android/Shuttle2/taglib/lib/src/main/cpp/../../../distribution/taglib/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=gnu++11 -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/file-scanner.dir/FileScanner.cpp.o -MF CMakeFiles/file-scanner.dir/FileScanner.cpp.o.d -o CMakeFiles/file-scanner.dir/FileScanner.cpp.o -c /Users/tim/Projects/Android/Shuttle2/taglib/lib/src/main/cpp/FileScanner.cpp
In file included from /Users/tim/Projects/Android/Shuttle2/taglib/lib/src/main/cpp/FileScanner.cpp:18:
/Users/tim/Projects/Android/Shuttle2/taglib/lib/src/main/cpp/unique_fd.h:112:13: error: use of undeclared identifier 'android_fdsan_exchange_owner_tag'
if (android_fdsan_exchange_owner_tag) {
Я использую CMake 3.10.2 и ndkVersion 21.0.6011959 RC2. Я компилирую, нацеливаюсь и работаю на Android 29.
Файл заголовка, ссылающийся на fdsan, выглядит следующим образом:
#pragma once
#include <android/fdsan.h>
#include <unistd.h>
#include <utility>
struct unique_fd {
unique_fd() = default;
explicit unique_fd(int fd) {
reset(fd);
}
unique_fd(const unique_fd& copy) = delete;
unique_fd(unique_fd&& move) {
*this = std::move(move);
}
~unique_fd() {
reset();
}
unique_fd& operator=(const unique_fd& copy) = delete;
unique_fd& operator=(unique_fd&& move) {
if (this == &move) {
return *this;
}
reset();
if (move.fd_ != -1) {
fd_ = move.fd_;
move.fd_ = -1;
// Acquire ownership from the moved-from object.
exchange_tag(fd_, move.tag(), tag());
}
return *this;
}
int get() { return fd_; }
int release() {
if (fd_ == -1) {
return -1;
}
int fd = fd_;
fd_ = -1;
// Release ownership.
exchange_tag(fd, tag(), 0);
return fd;
}
void reset(int new_fd = -1) {
if (fd_ != -1) {
close(fd_, tag());
fd_ = -1;
}
if (new_fd != -1) {
fd_ = new_fd;
// Acquire ownership of the presumably unowned fd.
exchange_tag(fd_, 0, tag());
}
}
private:
int fd_ = -1;
// The obvious choice of tag to use is the address of the object.
uint64_t tag() {
return reinterpret_cast<uint64_t>(this);
}
// These functions are marked with __attribute__((weak)), so that their
// availability can be determined at runtime. These wrappers will use them
// if available, and fall back to no-ops or regular close on pre-Q devices.
static void exchange_tag(int fd, uint64_t old_tag, uint64_t new_tag) {
if (android_fdsan_exchange_owner_tag) {
android_fdsan_exchange_owner_tag(fd, old_tag, new_tag);
}
}
static int close(int fd, uint64_t tag) {
if (android_fdsan_close_with_tag) {
return android_fdsan_close_with_tag(fd, tag);
} else {
return ::close(fd);
}
}
};
Любая помощь будет принята с благодарностью.