Android跨平台编译 —— filesystem

前言

    前言都在 Android跨平台编译 —— BOOST

 

正文

    弄完了iconv 和boost,以为大公告成,编译代码,发现有出错了…………

......
src/main/cpp/shared/tkat/CMakeFiles/TKAT.dir/src/filesystem.cpp.o: In function `std::experimental::filesystem::v1::exists(std::experimental::filesystem::v1::path const&)':
/Users/yxwang/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/experimental/filesystem:1473: undefined reference to `std::experimental::filesystem::v1::__status(std::experimental::filesystem::v1::path const&, std::__ndk1::error_code*)'
src/main/cpp/shared/tkat/CMakeFiles/TKAT.dir/src/filesystem.cpp.o: In function `std::experimental::filesystem::v1::is_empty(std::experimental::filesystem::v1::path const&)':
/Users/yxwang/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/experimental/filesystem:1560: undefined reference to `std::experimental::filesystem::v1::__fs_is_empty(std::experimental::filesystem::v1::path const&, std::__ndk1::error_code*)'
src/main/cpp/shared/tkat/CMakeFiles/TKAT.dir/src/filesystem.cpp.o: In function `std::experimental::filesystem::v1::status(std::experimental::filesystem::v1::path const&)':
/Users/yxwang/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/experimental/filesystem:1735: undefined reference to `std::experimental::filesystem::v1::__status(std::experimental::filesystem::v1::path const&, std::__ndk1::error_code*)'
src/main/cpp/s
.....

    发现std::experimental::filesystem::v1::path 这些没有实现。

    我们在头文件中是这么引用这些方法的

# elif __has_include(<experimental/filesystem>)
#   include <experimental/filesystem>
#   define TKAT_EXPERIMENTAL_FILESYSTEM
# elif __has_include(<boost/filesystem.hpp>)
#   include <boost/filesystem.hpp>
#   define TKAT_BOOST_FILESYSTEM
# else
#   error "cannot find <filesystem> or <experimental/filesystem> or <boost/filesystem.hpp>"
# endif

    如果存在experimental/filesystem的头文件,那么直接使用系统提供的,如果不存在,那么使用boost中的filesystem。

    然后我们发现android是提供了experimental/filesystem头文件的,所以理所当然使用系统提供的。

    这个头文件定义ndk-bundle/sources/cxx-stl/llvm-libc++/include/experimental/filesystem 中,并且确实定义了这些方法。

    问题是没有实现?为什么没有实现,源代码你也能够在ndk-bundle/sources/cxx-stl/llvm-libc++/src/experimental/filesystem这个路径找到……

    这个时候请看这里

https://github.com/android-ndk/ndk/issues/609

    回答很关键

"libc++ compiles its experimental parts into libc++experimental, a library that you need to link in separately. Unfortunately, we don't seem to build it as part of the NDK. Retitling the bug to look into shipping it.

In the mean time, you might be able to just add the required files directly into your project (from $ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/src/experimental/filesystem) to work around this on your end, but I haven't tried it (and this is guaranteed to break in the future, when the files are moved into the standard or abandoned)."

    大意就是experimental没有包含在libc++中的,而是包含在额外的libc++experimental中的。但是在ndk r16中并没有主动编译并且提供libc++experimental这个库。

    解决方案还是需要用户复制代码出来手动编译…………

    于是做了如下目录结构,然后手动在cmake中编译

184935_1JQR_2398062.png

aux_source_directory(${PROJECT_SOURCE_DIR}/src/main/cpp/experimental/filesystem filesystem_dir)

    add_library(
        myfilesystem
        STATIC
        ${filesystem_dir}
    )

    然后在需要的地方直接target_link这个myfilesystem即可

target_link_libraries(TKAT PRIVATE myfilesystem)

转载于:https://my.oschina.net/zzxzzg/blog/1621391

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值