CMakeTestCCompiler.cmake错误解决

最近编译项目的时候,遇到一个cmake的错误,具体错误信息如下:

/path-to-project/src/main/cpp/CMakeLists.txt : C/C++ debug|armeabi : CMake Error at /home/tools/Sdk/cmake/3.10.2.4988404/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/home/tools/android-ndk-r16b/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: /path-to-peject/.cxx/cmake/debug/armeabi/CMakeFiles/CMakeTmp
    
    Run Build Command:"/home/tools/Sdk/cmake/3.10.2.4988404/bin/ninja" "cmTC_c3844"
    [1/2] Building C object CMakeFiles/cmTC_c3844.dir/testCCompiler.c.o
    FAILED: CMakeFiles/cmTC_c3844.dir/testCCompiler.c.o 
    /home/tools/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv5te-none-linux-androideabi --gcc-toolchain=/home/tools/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/tools/android-ndk-r16b/sysroot   -isystem /home/tools/android-ndk-r16b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=16 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security   -fPIE -o CMakeFiles/cmTC_c3844.dir/testCCompiler.c.o   -c testCCompiler.c
    /home/tools/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
    ninja: build stopped: subcommand failed.
    

  

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

遇到这个问题,首先我们看到报错的位置在CMakeTestCCompiler.cmake的52行。我们在sdk的cmake中找到这个位置:

if(NOT CMAKE_C_COMPILER_WORKS)
  PrintTestCompilerStatus("C" " -- broken")
  file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
    "Determining if the C compiler works failed with "
    "the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n")
  string(REPLACE "\n" "\n  " _output "${__CMAKE_C_COMPILER_OUTPUT}")
  message(FATAL_ERROR "The C compiler\n  \"${CMAKE_C_COMPILER}\"\n"
    "is not able to compile a simple test program.\nIt fails "
    "with the following output:\n  ${_output}\n\n"
    "CMake will not be able to correctly generate this project.")
else()

if(NOT CMAKE_C_COMPILER_WORKS)我们可以知道,是因为编译器不能正常工作。从CMakeTestCCompiler这个名字可以发现,应该是cmake正在测试编译器到底能不能正常工作。

这时候我突然想起,我是新装的ubuntu系统,可能是一些编译工具还没有安装导致的。所以首先执行如下命令:

sudo apt install build-essential

build-essential中包含gcc,g++等编译工具。

但是安装这些工具后,还是会报相同的错误。

我们接着往下看报错信息:

  The C compiler

    "/home/tools/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"

  is not able to compile a simple test program.

可以发现并不是报的gcc/g++编译器的错误,而是报的ndk中的clang的错误,是linux-x64_64平台的。但是ndk是从官方网站下载的,应该不会出问题。

我们接着往下看报错信息:

/home/tools/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang: 
error while loading shared libraries: libncurses.so.5: 
cannot open shared object file: No such file or directory

我们发现是找不到libncurses.so.5这个动态库。使用如下命令安装这个库之后,问题就解决了:

sudo apt-get install libncurses5:i386
sudo apt-get install libncurses5

所以这里有个疑问:

既然ndk需要这个库,为什么不内置呢?

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐