在虚拟机的共享文件夹中,用NDK编译库文件遇到的问题

用虚拟机在共享文件夹中,NDK编译库文件遇到的问题

场景

项目需要把业务代码封装成Android环境调用的库.so文件

编译时出现的错误:

CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.

– ANDROID_PLATFORM not set. Defaulting to minimum supported version
16.
– Check for working C compiler: /usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
– Check for working C compiler: /usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - broken
CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler

"/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /mnt/hgfs/lib_src/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_16f32/fast && /usr/bin/make -f CMakeFiles/cmTC_16f32.dir/build.make CMakeFiles/cmTC_16f32.dir/build
make[1]: Entering directory '/mnt/hgfs/lib_src/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_16f32.dir/testCCompiler.c.o
/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi16 --gcc-toolchain=/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/sysroot   -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   -fPIE   -o CMakeFiles/cmTC_16f32.dir/testCCompiler.c.o   -c /mnt/hgfs/lib_src/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_16f32
/home/shark/cmake/cmake-3.17.0-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_16f32.dir/link.txt --verbose=1
/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi16 --gcc-toolchain=/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/sysroot -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    -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,--gc-sections   CMakeFiles/cmTC_16f32.dir/testCCompiler.c.o  -o cmTC_16f32  -latomic -lm 
/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: fatal error: cmTC_16f32: 输入/输出错误
clang: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/cmTC_16f32.dir/build.make:103: recipe for target 'cmTC_16f32' failed
make[1]: *** [cmTC_16f32] Error 1
make[1]: Leaving directory '/mnt/hgfs/lib_src/CMakeFiles/CMakeTmp'
Makefile:138: recipe for target 'cmTC_16f32/fast' failed
make: *** [cmTC_16f32/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (PROJECT)

– Configuring incomplete, errors occurred!
See also “/mnt/hgfs/lib_src/CMakeFiles/CMakeOutput.log”.
See also “/mnt/hgfs/lib_src/CMakeFiles/CMakeError.log”.
make: *** 没有指明目标并且找不到 makefile。 停止。

解决方法

不在这个路径编译代码/mnt/hgfs/lib_src,直接把代码拷贝到虚拟机中,再次编译就可以正常生成目标库文件。我把工程拷贝到虚拟机后,编译的过程中还出现了新的问题,问题和解决方法如下:

再次编译又出现新的问题

CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:168 (file):
file failed to open for writing (No such file or directory):

/home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/CMakeOutput.log

Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:170 (file):
file failed to open for writing (No such file or directory):

/home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/CMakeOutput.log

Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error: Could not open file for write in copy operation /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/3.17.0/CMakeSystem.cmake.tmp
CMake Error: : System Error: No such file or directory
CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:185 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error: Could not open file for write in copy operation /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/3.17.0/CMakeCCompiler.cmake.tmp
CMake Error: : System Error: No such file or directory
CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeDetermineCCompiler.cmake:212 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error: Could not find cmake module file: /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/3.17.0/CMakeCCompiler.cmake
CMake Error: Could not open file for write in copy operation /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/3.17.0/CMakeCXXCompiler.cmake.tmp
CMake Error: : System Error: No such file or directory
CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeDetermineCXXCompiler.cmake:210 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error: Could not find cmake module file: /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/3.17.0/CMakeCXXCompiler.cmake
– Check for working C compiler: /usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:32 (file):
file failed to open for writing (No such file or directory):

/home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/CMakeTmp/testCCompiler.c

Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:44 (try_compile):
Unknown extension “.c” for file

/home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/CMakeTmp/testCCompiler.c

try_compile() works only for enabled languages. Currently these are:

C CXX

See project() command to enable other languages.
Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

– Check for working C compiler: /usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - broken
CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:56 (file):
file failed to open for writing (No such file or directory):

/home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeFiles/CMakeError.log

Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

CMake Error at /home/shark/cmake/cmake-3.17.0-Linux-x86_64/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler

"/usr/android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"

is not able to compile a simple test program.

It fails with the following output:

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:5 (PROJECT)

– Configuring incomplete, errors occurred!
CMake Error: Cannot open file for write: /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. /home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src/CMakeCache.txt
CMake Error: : System Error: Permission denied
----------------------------cmake android debug1 /usr/android/android-ndk-r21----------------------------
make: *** 没有指明目标并且找不到 makefile。 停止。

解决方法

工程拷贝到这个路径后编译/home/shark/project/project_src/02_ProjectCode/01_SourceCode/module/lib/lib_src 会出现上面的问题,解决方法是,把路径改短一点,改为/home/shark/lib_src 后再次编译,就可以正常编译通过了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值