正在获取clang ++:错误:编译包含文件系统库的代码时

问题描述 投票:0回答:2

我正在尝试在android项目的本机代码中使用文件系统。但是出现此错误:

失败:

C:/Users/Johnsnow/AndroidStudioProjects/abc/Application/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib1.so 
cmd.exe /C "cd . && C:\Users\Johnsnow\AppData\Local\Android\Sdk\ndk\21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/Users/Johnsnow/AppData/Local/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/Johnsnow/AppData/Local/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -stdlib=libc++ -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libnative-lib1.so -o C:\Users\Johnsnow\AndroidStudioProjects\abc\Application\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib1.so @CMakeFiles/native-lib1.rsp  && cd ."
C:/Users/Johnsnow/AppData/Local/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1/filesystem:1615: error: undefined reference to 'std::__ndk1::__fs::filesystem::__status(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::error_code*)'
C:/Users/Johnsnow/AppData/Local/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1/filesystem:1637: error: undefined reference to 'std::__ndk1::__fs::filesystem::__file_size(std::__ndk1::__fs::filesystem::path const&, std::__ndk1::error_code*)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

我包括的方式是:

#include <filesystem>

在我使用的c ++代码中:

std::filesystem::path

cmake build.gradle中的内容:

externalNativeBuild {
            cmake {
                arguments '-DANDROID_PLATFORM=android-16',
                        '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_shared'
            }
        }

尝试的选项:

我已经尝试在cmakeLists.txt中添加libc ++

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

也尝试过:

target_link_libraries(native-lib1 -lstdc++)

也尝试过:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++")

其中native-lib1是我要添加的库。但这是行不通的。我的NDK版本是:21.1.6352462

请提出一些解决方法。

c++ cmake android-ndk
2个回答
1
投票

[为了使std::filesystem正常工作,我将解决方案平台更改为x64,而不是默认的Win32

我是在控制台应用程序的Visual Studio上完成的。

但是,我希望这会有所帮助。


0
投票

[std::filesystem的支持看起来将在Android NDK r22 at the earliest中出现:

现在已将其实现签入master,并将在r22中进行。我将其余的测试清理工作分叉到#1265中,因此我可以关闭它以使您清楚地知道您关心的部分已经完成,而无需阅读整个过程:)

链接的线程有一些解决方法,例如使用boost::filesystem或仅自行构建std::filesystem库(libc++fs)。

© www.soinside.com 2019 - 2024. All rights reserved.