CMake/Android error: "not able to compile a simple test program" - android

I am trying to compile a CMake project for android.
I use QtCreator to create and compile the project. Using QMake works fine, but CMake projects don't work.
CMake Project parsing failed.
Running "C:\Android\android-sdk\cmake\3.10.2.4988404\bin\cmake.exe -E server "--pipe=\\.\pipe\{78eb9a25-fbdf-4ac7-b840-8cfe89cbd883}" --experimental" in C:\Users\Thorsten\AppData\Local\Temp\QtCreator-Zmienl\qtc-cmake-KUabkXqG.
Starting to parse CMake project, using: "-DCMAKE_CXX_COMPILER:STRING=C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe", "-DCMAKE_C_COMPILER:STRING=C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe", "-DCMAKE_PREFIX_PATH:STRING=C:/Qt/5.13.0/android_x86_64", "-DQT_QMAKE_EXECUTABLE:STRING=C:/Qt/5.13.0/android_x86_64/bin/qmake.exe".
The CXX compiler identification is Clang 8.0.2
Check for working CXX compiler: C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
Check for working CXX compiler: C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- broken
CMake Error at C:/Android/android-sdk/cmake/3.10.2.4988404/share/cmake-3.10/Modules/CMakeTestCXXCompiler.cmake:45 (message):
The C++ compiler
"C:/Android/android-sdk/ndk-bundle/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: C:/Users/Thorsten/AppData/Local/Temp/QtCreator-Zmienl/qtc-cmake-KUabkXqG/CMakeFiles/CMakeTmp
Run Build Command:"C:/Android/android-sdk/cmake/3.10.2.4988404/bin/ninja.exe" "cmTC_622f7"
[1/2] Building CXX object CMakeFiles/cmTC_622f7.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_622f7.exe
FAILED: cmTC_622f7.exe
cmd.exe /C "cd . && C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe CMakeFiles/cmTC_622f7.dir/testCXXCompiler.cxx.obj -o cmTC_622f7.exe -Wl,--out-implib,libcmTC_622f7.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
clang++.exe: error: unable to execute command: program not executable
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
Configuring incomplete, errors occurred!
See also "C:/Users/Thorsten/AppData/Local/Temp/QtCreator-Zmienl/qtc-cmake-KUabkXqG/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Thorsten/AppData/Local/Temp/QtCreator-Zmienl/qtc-cmake-KUabkXqG/CMakeFiles/CMakeError.log".
CMake Project parsing failed.
I found several posts about this, but most of them were not answered or simply not useful. I found this helpful, so I added
SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)
before project(). But now I get
CMake Error in CMakeLists.txt:
No known features for CXX compiler
"Clang"
version 8.0.2.
CMake Project parsing failed.
So far I haven't found something useful for that.
I hope I can get some more help this way.
ps: I recently reinstalled my os (Windows 10), so if I forgot to update something it's not older than two month. I let QtCreator, Visual Studio and Android Studio do the installation of the toolchains.
pps: The project is a new project created by QtCreator

Related

Having trouble building a very simple OpenCV C++ .so library using CMake for use on Android

I am trying to use CMake to create a .so library that uses OpenCV for use on Android.
I have no prior experience with CMake before this. I got a couple things working with CMake so far. I successfully built and ran a simple OpenCV program for windows and I've also created a .so file that doesn't use OpenCV. I was able to successfully called that .so from a Unity program on Android. My goal is to create an OpenCV plugin for Unity. I turned to CMake because I tried making a simple .so in Visual Studios, but my Unity program couldn't find it (though I was able to create a .dll that used OpenCV for a windows Unity program using Visual Studios that worked).
I have both r19c Android NDK and OpenCV 4.5.2 Android SDK on my C drive.
My code file is test.cpp, and it very simply uses some OpenCV elements. It's as follows:
#include "opencv2/opencv.hpp"
extern "C" int get_number()
{
cv::Mat img(2,2, CV_8UC3, cv::Scalar(126,0,255));
cv::Size size = img.size();
int width = size.width;
return width;
}
I am thinking that my error may be in the CMakeLists.txt file, that I am probably pointing to the wrong OpenCV folders.
My CMakeLists.txt is:
cmake_minimum_required(VERSION 3.20)
set(OpenCV_DIR C:/OpenCVAndroid/sdk/native/jni/abi-arm64-v8a)
set(OpenCV_INCLUDE_DIRS C:/OpenCVAndroid/sdk/native/jni/include)
project( test )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_library( test SHARED test.cpp )
and I'm using a .bat file that has the following lines:
rmdir /s /q build
mkdir build
cd build
"C:/Program Files/CMake/bin/cmake.exe" ^
-S=C:\Users\m_knu\Desktop\test ^
-G"MinGW Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_TOOLCHAIN_FILE=C:\r19c\android-ndk-r19c\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=C:\r19c\android-ndk-r19c\prebuilt\windows-x86_64\bin\make.exe ^
-DANDROID_NDK=C:\r19c\android-ndk-r19c ^
-DANDROID_NATIVE_API_LEVEL=android-21 ^
-DANDROID_ABI=arm64-v8a ^
-DCMAKE_MODULE_PATH="C:/OpenCVAndroid/sdk/native/jni/abi-armeabi-v7a" ^
"C:/Program Files/CMake/bin/cmake.exe" --build .
pause
all three files are located in the same folder.
When I run the .bat file I get the following output:
C:\Users\m_knu\Desktop\test>rmdir /s /q build
C:\Users\m_knu\Desktop\test>mkdir build
C:\Users\m_knu\Desktop\test>cd build
C:\Users\m_knu\Desktop\test\build>"C:/Program Files/CMake/bin/cmake.exe" -S=C:\Users\m_knu\Desktop\test -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:\r19c\android-ndk-r19c\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\r19c\android-ndk-r19c\prebuilt\windows-x86_64\bin\make.exe -DANDROID_NDK=C:\r19c\android-ndk-r19c -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_ABI=arm64-v8a -DCMAKE_MODULE_PATH="C:/OpenCVAndroid/sdk/native/jni/abi-armeabi-v7a"
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/r19c/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/r19c/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: C:/OpenCVAndroid (found version "4.5.2")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/m_knu/Desktop/test/build
C:\Users\m_knu\Desktop\test\build>"C:/Program Files/CMake/bin/cmake.exe" --build .
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.o
[100%] Linking CXX shared library libtest.so
CMakeFiles/test.dir/test.cpp.o: In function `get_number':
C:\Users\m_knu\Desktop\test/test.cpp:5: undefined reference to `cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&)'
C:\Users\m_knu\Desktop\test/test.cpp:9: undefined reference to `cv::Mat::~Mat()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libtest.so] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
C:\Users\m_knu\Desktop\test\build>pause
Press any key to continue . . .
As I mentioned earlier, my guess is that I've incorrectly referenced the OpenCV directories, but I wouldn't be surprised if I'm missing other things.

Docker. Build NDK project. The detected version of Ninja () is less than the version of Ninja required by CMake (1.3)

I have project that recently start using ndk. I have CI worked with Docker. After adding ndk to my project I added ndk to docker file, however for now I see problem with Ninja version.
Here's log output
-- Check for working C compiler: /android-ndk-linux/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
CMake Error:
The detected version of Ninja () is less than the version of Ninja required
by CMake (1.3).
CMake Error: Internal CMake error, TryCompile generation of cmake failed
-- Check for working C compiler: /android-ndk-linux/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- broken
CMake Error at /sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler
"/android-ndk-linux/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" is not
able to compile a simple test program.
Did anyone faced with the same problem? Here's link for my docker file on docker hub https://cloud.docker.com/repository/docker/relgang/ndkfastlane

Cmake not able to compile simple test program on qt creator / collect2: error: ld

I am trying to build an Android project using the android NDK.
I have added the NDK to the QT Versions, the build kit was auto detected but when running CMake I get the following error:
Starting to parse CMake project, using: "-DCMAKE_CXX_COMPILER:STRING=/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-g++", "-DCMAKE_C_COMPILER:STRING=/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc", "-DCMAKE_PREFIX_PATH:STRING=/home/self/Qt5.9.6/5.9.6/android_x86", "-DQT_QMAKE_EXECUTABLE:STRING=/home/self/Qt5.9.6/5.9.6/android_x86/bin/qmake".
The C compiler identification is GNU 4.9.0
The CXX compiler identification is GNU 4.9.0
Check for working C compiler: /home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc
Check for working C compiler: /home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /tmp/QtCreator-Tuub3S/qtc-cmake-XXSZ1kmJ/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/ninja" "cmTC_991f8"
[1/2] Building C object CMakeFiles/cmTC_991f8.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_991f8
FAILED: cmTC_991f8
: && /home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc -rdynamic CMakeFiles/cmTC_991f8.dir/testCCompiler.c.o -o cmTC_991f8 && :
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot find -lc
/home/self/Downloads/addis/android-ndk-r17b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
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 "/tmp/QtCreator-Tuub3S/qtc-cmake-XXSZ1kmJ/CMakeFiles/CMakeOutput.log".
See also "/tmp/QtCreator-Tuub3S/qtc-cmake-XXSZ1kmJ/CMakeFiles/CMakeError.log".
CMake Project parsing failed.
What am I doing wrong?
EDIT So as suggested I downloaded NDK 10e ... Problem seems to stay the same:
/usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52: error: The C compiler "/home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc" is not able to compile a simple test program.
It fails with the following output: Change Dir: /tmp/QtCreator-vkcYcW/qtc-cmake-XXyT08En/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/ninja" "cmTC_3ab69"
[1/2] Building C object CMakeFiles/cmTC_3ab69.dir/testCCompiler.c.o
[2/2] Linking C executable cmTC_3ab69 FAILED: cmTC_3ab69 : && /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc -rdynamic CMakeFiles/cmTC_3ab69.dir/testCCompiler.c.o -o cmTC_3ab69 && :
/home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-androi.d/4.9/../../../../i686-linux-android/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot open crtend_android.o: No such file or directory /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot find -lc /home/self/Android/android-ndk-r10e/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
Qt does not support a recent version of NDK, in the docs it is recommended to use NDK 10e

Cricket audio engine CMAKE

Did anyone implemeted Cricket audio engine (http://www.crickettechnology.com/blog/) for Android Studio using gradle and Cmake (Android NDK) ?
I have imported the lib in my Cmake like this:
target_link_libraries(test
${CMAKE_CURRENT_SOURCE_DIR}/../../test/cricketaudio/lib/libck.a)
And the compiler sees it alright but when I try to run it, the linker gives me this error:
Error while executing process
[1/1] Linking CXX shared library
..\..\..\..\build\intermediates\cmake\development\debug\obj\armeabi-
v7a\libtest.so
FAILED: cmd.exe -soname,libtest.so -o
..\..\..\..\build\intermediates\cmake\development\debug\obj\armeabi-
v7a\libtest.so #CMakeFiles/test.rsp && cd ."
core/system_android.cpp:174: error: undefined reference to
'android_getCpuFamily'
core/system_android.cpp:187: error: undefined reference to
'android_getCpuFeatures'
core/system_android.cpp:210: error: undefined reference to
'android_getCpuCount'
clang++.exe: error: linker command failed with exit code 1 (use -v to see
invocation)
ninja: build stopped: subcommand failed.
I am aware that libck (cricket audio) has a dependency lib the Android NDK cpufeauters lib which is located in the Android NDK bundle (Android\Sdk\ndk-bundle\sources\android\cpufeatures).
I don`t know how to make this cpufeatures lib visible to the Linker of my project ???
Any help or pointers would be appreciated.
I have simply included the cpu-features.c and header file to my cmakelist and now it works :).

Android Studio Gradle Fail

I tried to build my android project, I got this error message.
Error while executing 'C:\Users\Chen\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {-HC:\Users\Chen\Desktop\Project\IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160\IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160\IPS_Android\app -BC:\Users\Chen\Desktop\Project\IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160\IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160\IPS_Android\app.externalNativeBuild\cmake\release\armeabi -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi -DANDROID_NDK=C:\Users\Chen\AppData\Local\Android\Sdk\ndk-bundle -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Chen\Desktop\Project\IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160\IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160\IPS_Android\app\build\intermediates\cmake\release\obj\armeabi -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=C:\Users\Chen\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\Users\Chen\AppData\Local\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=15 -DCMAKE_CXX_FLAGS=}
-- Check for working C compiler: C:/Users/Chen/AppData/Local/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Users/Chen/AppData/Local/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken
-- Configuring incomplete, errors occurred!
CMake Error: Could not open file for write in copy operation C:/Users/Chen/Desktop/Project/IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160/IPS-Competition-master-326592647c34e3535eb78372bea8ec1c58ca6160/IPS_Android/app/.externalNativeBuild/cmake/release/armeabi/CMakeFiles/3.6.0-rc2/CMakeCCompiler.cmake.tmp
CMake Error: : System Error: No such file or directory
I've installed CMAKE, LLDB, NDK. Can I get some help?
Thanks.
I think you need to install compiler driver of c++.

Categories

Resources