简体   繁体   中英

CMake using two different NDK, why is it broken?

I am trying to build the ceres-library on android. I am following the instructions been given on the website, but I got stuck with an error and I don't understand why.

I am not an expert in building tools so I do apologize if my question is trivial but I'd like to know why it's not working.

Essentially what happens is that cmake for some reason is using the NDK I've installed with android studio but also the NDK that comes with visual studio if you enable the android development features.

My question first of all is why is using it both? (I would assume I have something broken in my setup but I cannot manage to fix it).

The command line I've been running is the following:

cmake -DCMAKE_TOOLCHAIN_FILE="C:\Users\l.gagliano\AppData\Local\Android\Sdk\ndk\16.1.4479499\build\cmake\android.toolchain.cmake" -DEigen3_DIR=D:\DEV\ceres\eigen\build -DANDROID_ABI=arm64-v8a -DANDROID_STL=c++_shared -DANDROID_NATIVE_API_LEVEL=android-21 -DBUILD_SHARED_LIBS=ON -DMINILOG=ON D:\DEV\ceres\ceres-solver-2.1.0

But I get the following output:

-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Users/l.gagliano/AppData/Local/Android/Sdk/ndk/16.1.4479499/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/l.gagliano/AppData/Local/Android/Sdk/ndk/16.1.4479499/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message):
  The C compiler

    "C:/Users/l.gagliano/AppData/Local/Android/Sdk/ndk/16.1.4479499/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: D:/DEV/ceres/ceres-android/CMakeFiles/CMakeScratch/TryCompile-lab0em

    Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe cmTC_366ff.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

      ANDROID_HOME=C:\\Microsoft\AndroidSDK\25
      ANT_HOME=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Apps\apache-ant-1.9.3
      JAVA_HOME=C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot
      NDK_ROOT=C:\\Microsoft\AndroidNDK64\android-ndk-r16b
      testCCompiler.c
      In file included from <built-in>:327:
    <command line>(3,9): warning : '__ANDROID_API__' macro redefined [-Wmacro-redefined] [D:\DEV\ceres\ceres-android\CMakeFiles\CMakeScratch\TryCompile-lab0em\cmTC_366ff.vcxproj]
      #define __ANDROID_API__ 21
              ^
      <command line>(1,9):  note: previous definition is here
      #define __ANDROID_API__ 19
              ^
      1 warning generated.
      C:\\Microsoft\AndroidNDK64\android-ndk-r16b\toolchains\x86_64-4.9\prebuilt\windows-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin\ld: error: cmTC_366ff.dir\Debug\testCCompiler.o: incompatible target
      clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Application Type\Android\3.0\Android.Common.targets(119,5): error MSB6006: "clang.exe" exited with code 1. [D:\DEV\ceres\ceres-android\CMakeFiles\CMakeScratch\TryCompile-lab0em\cmTC_366ff.vcxproj]





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


-- Configuring incomplete, errors occurred!
See also "D:/DEV/ceres/ceres-android/CMakeFiles/CMakeOutput.log".
See also "D:/DEV/ceres/ceres-android/CMakeFiles/CMakeError.log".

The command line comes from the example given in the Ceres Android section.

Obviously my end goal, apart from understanding the error, is actually fixing it so any suggestion would be appreciated.

This sorted:

cmake -G "Visual Studio 16" -A arm64 -DCMAKE_PREFIX_PATH=D:\DEV\ceres\gflags\build-gflags -DCMAKE_TOOLCHAIN_FILE="C:\Users\l.gagliano\AppData\Local\Android\Sdk\ndk\16.1.4479499\build\cmake\android.toolchain.cmake" -DEigen3_DIR=D:\DEV\ceres\eigen\build -DANDROID_ABI=arm64-v8a -DANDROID_STL=c++_shared -DANDROID_NATIVE_API_LEVEL=android-21 -DBUILD_SHARED_LIBS=ON -DMINIGLOG=ON D:\DEV\ceres\ceres-solver-2.1.0

Mainly the -G "Visual Studio 16" -A arm64 was the big deal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM