18

I've successfully configured and built some Qt5 applications for Android using CMake and this CMake utility.

Everything worked fine until I switched from Qt5.6 to Qt5.7. When I try to configure I get an CMake error which doesn't help me much:

-- Configuring done
CMake Error in CMakeLists.txt:
  No known features for CXX compiler

  "GNU"

  version 4.9.

-- Generating done
-- Build files have been written to: /path/to/build-dir

I run CMake like this:

ANDROID_SDK=/path/to/android-sdk-linux \
ANDROID_NDK=/path/to/android-ndk-r12 \
QT_ANDROID_ROOT=/path/to/Qt-5.7.0-android \
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk \
ANT=/usr/bin/ant \
cmake /path/to/CMakeLists.txt \
      -DCMAKE_PREFIX_PATH=$QT_ANDROID_ROOT \
      -DCMAKE_TOOLCHAIN_FILE=/path/to/android.toolchain.cmake

I can reproduce this behavior with a minimal C++ program:

#include <iostream>
int main() { std::cout << "hi" << std::endl; }

and a minimal CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)
find_package(Qt5Core)
add_executable(foo main.cpp)
target_link_libraries(foo Qt5::Core)

The line that introduces this error is target_link_libraries(foo Qt5::Core) - without it the program configures and compiles fine.

Here are some things I tried:

  • use different NDK API levels by setting ANDROID_NATIVE_API_LEVEL to android-8, 9, 16, 18 and some other values that worked somwhere else (building Qt5.7 automatically uses android-16)

  • use different NDK releases (10e worked for me with Qt5.6, current is 12)

  • tried prebuilt Qt5.7 rather than home-grown from GitHub

Until now I just combined different versions of SDK/NDK/Qt/NDK_API_LEVEL but honestly I just don't know what I'm doing..

You could help me by:

  • telling me what I've done wrong (best!)
  • elaborate on that CMake error to give me a hint
  • provide me with a working CMake/Android/Qt5.7 example which I can use myself to find the problem
frans
  • 8,868
  • 11
  • 58
  • 132
  • Same problem, was searching for a whole afternoon. With Qt5.6.1 all works fine but same toolchain with Qt5.7.0 gives me the same error as yours. Also tried cmake 3.5.2 with no more luck. – Falco Jul 03 '16 at 23:52
  • @frans: If I were you, I would drop qt-android-cmake and write the .pro file manually from my CMake scripts. That's what I do and it's pretty obvious to write .pro file yourself as the syntax is very simple...it would require you some work but may be a better solution long term... – jpo38 Jul 13 '16 at 10:11
  • Qt5.7 does a `set(CMAKE_CXX_STANDARD 11)` which makes cmake add a `-std=gnu++11`, so maybe your compiler is not liking it, if you can it could be worth trying to update your gcc version to 5.3 or something like this. – cmourglia Jul 13 '16 at 14:00
  • Also, I don't know if you are using QtCreator, but I remember having this kind of errors after letting the last version compile my stuff, I had to get a new totally clean directory of my work to make it compile again (from the command line, I won't run QtCreator anymore I think :D), might also be related to this. – cmourglia Jul 13 '16 at 14:04

5 Answers5

13

As a workaround (from here) you can comment out the line

set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)

in lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake file

cdovgal
  • 326
  • 3
  • 10
3

For me, the trick was to clean all configuration and temporary build files and force a reconfiguration of the project:

  • Close Qt Creator
  • Remove manually
    • Qt build folders
    • All .pro.user and .cmake.user files
    • All CMake build folders
  • Re-open the project
Adrien Leravat
  • 2,731
  • 18
  • 32
1

I agree that the message is not very helpful, so no my answer is a guess. It seems like cmake fails to detect your toolchain (GCC) correctly, and this is related to cmake internals, not necessarily your script.

I found a related question: "no known features for CXX compiler" when compiling with MSVC++ 2013

Also, if you google '"No known features for CXX compiler" cmake' there will be some bug reports for cmake in the search result.

What you can try is to update the cmake version, if one is available. If the problem persist I suggest to use the cmake-users mailing list or IRC channels to sort out the problem.

Community
  • 1
  • 1
Eirik M
  • 726
  • 1
  • 6
  • 12
0

The CMake utility you are using is not up-to-date anymore for the newer Qt and Android-NDK versions. Using it, I had the same problem as you have and I could not get it to work. However, replacing the CMake toolchain file delivered by the Android NDK, I could get everything to work and compile as wished.

oLen
  • 5,177
  • 1
  • 32
  • 48
-1

you have to setup "project(MyProject)" in CMakeFile.txt

I have same same error but project(Myproject) was in a if-statement. Moving it out fixed the problem:

CMakeList.txt error: cmake_minimum_required (VERSION 3.10) if(${SOMETHING}) project(MyProject) : endif

CMakeList.txt success: cmake_minimum_required (VERSION 3.10) project(MyProject) if(${SOMETHING}) : endif