简体   繁体   English

使用Xcode进行CMake:找不到已配置的头文件(.h.in)

[英]CMake with Xcode: configured header file (.h.in) not found

I'm working through the CMake tutorial and I'm up to the Adding a Version Number and Configured Header File section. 我正在完成CMake教程 ,我要做的添加版本号和配置的头文件部分。 Unfortunately Xcode isn't recognising the generated header file: 不幸的是,Xcode无法识别生成的头文件:

The error: 错误:

找不到'src / TutorialConfig'文件

The header file was generated by CMake ok: 头文件是由CMake ok生成的:

finder中的头文件

TutorialConfig.h.in TutorialConfig.h.in

// the configured options and settings for Tutorial

#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@

CMakeLists.txt 的CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project (Tutorial)
# The version number.
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  )

# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
include_directories("${PROJECT_BINARY_DIR}/src")

# add the executable
add_executable(Tutorial src/tutorial.cpp)

This is the tutorial I'm working from. 这是我正在使用的教程。

I don't use Xcode, but another IDE that's Linux based. 我不使用Xcode,而是使用基于Linux的另一个IDE。 But maybe I can help you a bit. 但也许我可以帮助你一点。 I'm just wondering -- does your program compile? 我只是想知道 - 你的程序是否编译? That's perhaps more important. 这可能更重要。

My IDE often complains about header files such as your's -- that is, configuration files that are generated by CMake. 我的IDE经常抱怨你的头文件 - 也就是CMake生成的配置文件。 Such warnings (at least for me) can be ignored. 这样的警告(至少对我而言)可以忽略不计。 I usually do because my build/ directory is sometimes empty. 我经常这样做,因为我的构建/目录有时是空的。 So when I've opened up the source file, there wouldn't be TutorialConfig.h yet. 所以当我打开源文件时,还没有TutorialConfig.h。

In fact, the IDE can never know about such header files. 实际上,IDE永远不会知道这样的头文件。 That's because it doesn't know which build/ directory you're going to compile your program in. 那是因为它不知道你要编译程序的构建/目录。

If you are worried by the warning, then there is probably a place where you can specify to Xcode which build/ directory to search for header files. 如果您对警告感到担心,那么可能有一个地方可以指定Xcode哪个构建/目录来搜索头文件。 That will remove the warning, after you've run CMake once. 在你运行一次CMake之后,这将删除警告。 However, removing such a warning is unreliable because you can always build in another directory that would have TutorialConfig.h missing. 但是,删除此类警告是不可靠的,因为您始终可以构建另一个缺少TutorialConfig.h的目录。

Hope this helps! 希望这可以帮助!

Oh, haha. 哦,哈哈。 I changed #include "src/TutorialConfig.h" to #include "TutorialConfig.h" and all is well. 我将#include "src/TutorialConfig.h"改为#include "TutorialConfig.h" ,一切都很顺利。 I figured it out by checking out the project settings: 我通过检查项目设置找出了它:

万岁!

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

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