简体   繁体   English

使用 CMake 为 Android 配置 Qt5 5.7 应用程序

[英]configure a Qt5 5.7 application for Android with CMake

I've successfully configured and built some Qt5 applications for Android using CMake and this CMake utility.我已经使用CMake这个CMake 实用程序成功地为Android配置和构建了一些 Qt5 应用程序。

Everything worked fine until I switched from Qt5.6 to Qt5.7 .一切正常,直到我从Qt5.6切换到Qt5.7 When I try to configure I get an CMake error which doesn't help me much:当我尝试配置时,我收到一个 CMake 错误,这对我没有多大帮助:

-- 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:我像这样运行 CMake:

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:我可以用最小的 C++ 程序重现这种行为:

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

and a minimal CMakeLists.txt :和一个最小的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.引入此错误的行是target_link_libraries(foo Qt5::Core) - 没有它,程序可以很好地配置和编译。

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 )通过将ANDROID_NATIVE_API_LEVEL设置为android-891618和其他一些在其他地方工作的值来使用不同的 NDK API 级别(构建 Qt5.7 自动使用android-16

  • use different NDK releases (10e worked for me with Qt5.6, current is 12)使用不同的NDK版本(10e 使用 Qt5.6 为我工作,当前为 12)

  • tried prebuilt Qt5.7 rather than home-grown from GitHub尝试预构建的 Qt5.7 而不是从 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..直到现在我只是结合了不同版本的 SDK/NDK/Qt/NDK_API_LEVEL 但老实说我只是不知道我在做什么..

You could help me by:你可以通过以下方式帮助我:

  • telling me what I've done wrong (best!)告诉我我做错了什么(最好!)
  • elaborate on that CMake error to give me a hint详细说明那个 CMake 错误给我一个提示
  • provide me with a working CMake/Android/Qt5.7 example which I can use myself to find the problem为我提供一个有效的 CMake/Android/Qt5.7 示例,我可以使用它来查找问题

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在 lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake 文件中

For me, the trick was to clean all configuration and temporary build files and force a reconfiguration of the project:对我来说,诀窍是清理所有配置和临时构建文件并强制重新配置项目:

  • Close Qt Creator关闭 Qt Creator
  • Remove manually手动移除
    • Qt build folders Qt 构建文件夹
    • All .pro.user and .cmake.user files所有.pro.user.cmake.user文件
    • All CMake build folders所有 CMake 构建文件夹
  • Re-open the project重新打开项目

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.似乎 cmake 无法正确检测您的工具链(GCC),这与 cmake 内部结构有关,不一定与您的脚本有关。

I found a related question: "no known features for CXX compiler" when compiling with MSVC++ 2013我发现了一个相关的问题: 使用 MSVC++ 2013 编译时“没有 CXX 编译器的已知功能”

Also, if you google '"No known features for CXX compiler" cmake' there will be some bug reports for cmake in the search result.此外,如果您在 google 上搜索“CXX 编译器没有已知功能”cmake',搜索结果中会出现一些 cmake 的错误报告。

What you can try is to update the cmake version, if one is available.您可以尝试更新 cmake 版本(如果有)。 If the problem persist I suggest to use the cmake-users mailing list or IRC channels to sort out the problem.如果问题仍然存在,我建议使用 cmake-users 邮件列表或 IRC 频道来解决问题。

The CMake utility you are using is not up-to-date anymore for the newer Qt and Android-NDK versions.您使用的 CMake 实用程序不再适用于较新的 Qt 和 Android-NDK 版本。 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.但是,替换由 Android NDK 提供的 CMake 工具链文件,我可以让一切正常工作并按照需要进行编译。

you have to setup " project(MyProject) " in CMakeFile.txt你必须在 CMakeFile.txt 中设置“ project(MyProject)

I have same same error but project(Myproject) was in a if-statement.我有同样的错误,但 project(Myproject) 在 if 语句中。 Moving it out fixed the problem:将其移出解决了问题:

CMakeList.txt error: cmake_minimum_required (VERSION 3.10) if(${SOMETHING}) project(MyProject) : endif CMakeList.txt 错误: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 CMakeList.txt 成功: cmake_minimum_required (VERSION 3.10) project(MyProject) if(${SOMETHING}) : endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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