【问题标题】:How to set up qt4 with cmake in Ubuntu?如何在 Ubuntu 中使用 cmake 设置 qt4?
【发布时间】:2020-06-07 18:10:58
【问题描述】:

我目前正在尝试设置 qt4 以在 CLion IDE 中使用 cmake,但是我无法指定安装路径。我正在运行 Ubuntu,所以我用sudo apt install qt4-default 下载了 qt4。这个安装在哪里?如何告诉 cmake 在哪里可以找到包配置文件?

这是我的 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.15)
project(ContactClasses)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp Contact.h Contact.cpp ContactList.h ContactList.cpp ContactFactory.h ContactFactory.cpp)
set(CMAKE_PREFIX_PATH "/usr/share/qt4")

find_package(Qt4Core REQUIRED)

add_executable(Homework_6 ${SOURCE_FILES})

target_link_libraries(ContactClasses Qt4::Core)

当我尝试重新加载时出现此错误:

CMake Error at CMakeLists.txt:8 (find_package):
  By not providing "FindQt4Core.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt4Core", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt4Core" with any
  of the following names:

    Qt4CoreConfig.cmake
    qt4core-config.cmake

  Add the installation prefix of "Qt4Core" to CMAKE_PREFIX_PATH or set
  "Qt4Core_DIR" to a directory containing one of the above files.  If
  "Qt4Core" provides a separate development package or SDK, be sure it has
  been installed.

【问题讨论】:

    标签: c++ ubuntu cmake qt4 clion


    【解决方案1】:

    CMake 中有一个专门的FindQt4 模块,请参阅它的documentation

    你这样称呼它:

    set(CMAKE_AUTOMOC ON)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    find_package(Qt4 REQUIRED QtCore)
    add_executable(Homework_6 ${SOURCE_FILES})
    target_link_libraries(Homework_6 PUBLIC Qt4::QtCore)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      • 1970-01-01
      相关资源
      最近更新 更多