【问题标题】:How to include header files in CMakeLists.txt in Qt Creator?如何在 Qt Creator 的 CMakeLists.txt 中包含头文件?
【发布时间】:2018-09-20 11:20:49
【问题描述】:

我正在使用 Qt Creator 学习 C++,没有使用任何 Qt 库,我只是使用 IDE。我创建了一个头文件,但它一直在说

此文件不属于任何项目

我知道它一定是 CMakeLists.txt 的内容,但我不知道该怎么做,或者为什么它没有自动包含。

cmake_minimum_required(VERSION 2.8)

project(S13V140_implementing_member_method)
add_executable(${PROJECT_NAME} "main.cpp")

???

【问题讨论】:

    标签: c++ qt cmake


    【解决方案1】:

    要让 CMake 和 Qt 一起工作,请确保将 all 标头添加到源文件列表中。

    set(sources "main.cpp" "my_header.h")
    add_executable(${PROJECT_NAME} ${sources})
    

    【讨论】:

      【解决方案2】:

      以下 CMakeLists.txt 应该适合您:

      cmake_minimum_required(VERSION 2.8)
      
      # define the project name
      project(S13V140_implementing_member_method)
      
      # find includes in corresponding build directories
      set(CMAKE_INCLUDE_CURRENT_DIR ON)
      
      # C++11 support - else we run into issues with the non-static nullptr-assignment
      set(CMAKE_CXX_STANDARD 11)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      # put all sources into one variable: no distinction between h, cpp and ui (or qrc)
      set(SOURCES
          main.cpp
      )
      
      # create the final result
      add_executable(S13V140_implementing_member_method ${SOURCES})
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-07
        • 2022-08-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多