简体   繁体   English

在 C++ CMake 项目中包含路径

[英]Include paths in C++ CMake project

I have included <time.h> in my C++ program I create in Eclipse C++ Cmake project that runs on Ubuntu. I have included <time.h> in my C++ program I create in Eclipse C++ Cmake project that runs on Ubuntu. I'm trying to navigate to <time.h> file, but get error could not find include file 'time.h' in include paths .我正在尝试导航到<time.h>文件,但出现错误could not find include file 'time.h' in include paths

Where I can set include paths in my C++ CMake project?我可以在C++ CMake项目中设置包含路径的位置?

time.h is a system header so even if Eclipse is not able to navigate to it the compiler should still be able to find it. time.h是一个系统 header 所以即使 Eclipse 无法导航到它,编译器仍然应该能够找到它。

Selecting Index -> Search For Unresolved Includes in the context menu of the project will give you the list of unresolved includes which you can search in /usr/include and add containing directories to C++ Include Paths and Symbols in Project Properties.在项目的上下文菜单中选择Index -> Search For Unresolved Includes将为您提供未解决的包含列表,您可以在/usr/include中搜索这些列表并将包含目录添加到C++ Include Paths and Symbols

On my system I had to add /usr/include/c++/4.6/x86_64-linux-gnu for bits/c++config.h to be resolved and a few more directories.在我的系统上,我必须添加/usr/include/c++/4.6/x86_64-linux-gnu来解析bits/c++config.h和更多目录。

Don't forget to rebuild the index (Index -> Rebuild) after adding include directories.添加包含目录后不要忘记重建索引(Index -> Rebuild)。

First, to tell CMake to add the directory as -I to the compilation command line, you use include directories().首先,要告诉 CMake 将目录作为 -I 添加到编译命令行,请使用 include commands()。 Second, in your add executable() or add library() call, you list the headers.其次,在您的 add executable() 或 add library() 调用中,您列出了标头。 When contrasted with other ways of making Makefile, CMake is more like a script language.与其他制作 Makefile 的方式相比,CMake 更像是一种脚本语言。

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

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