使用CMake为Android配置Qt5

使用CMake为Android配置Qt5

本文介绍了使用CMake为Android配置Qt5 5.7应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 CMake CMake实用工具.

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

一切正常,直到我从 Qt5.6 切换到 Qt5.7 .当我尝试配置时,出现CMake错误,对我没有太大帮助:

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

我这样运行CMake:

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

我可以使用最少的C ++程序重现此行为:

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

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

和最小的CMakeLists.txt:

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

引入此错误的行是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:

  • 通过将ANDROID_NATIVE_API_LEVEL设置为android-891618以及其他在其他地方起作用的其他值来使用不同的NDK API级别(构建Qt5.7会自动使用android-16 )

  • 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)

使用不同的NDK版本(10e在Qt5.6中对我有效,当前为12)

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

尝试使用预构建的Qt5.7,而不是从GitHub本地开发的

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

直到现在,我只是组合了不同版本的SDK/NDK/Qt/NDK_API_LEVEL,但说实话,我只是不知道自己在做什么.

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:

  • 告诉我我做错了(最好!)
  • 详细说明该CMake错误给我一个提示
  • 为我提供了一个有效的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)

在lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake文件中

in lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake file

这篇关于使用CMake为Android配置Qt5 5.7应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 15:11