Eclipse C ++包括我的源文件夹中的头文件 [英] Eclipse C++ including header file from my source folder

查看:210
本文介绍了Eclipse C ++包括我的源文件夹中的头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢C ++和Eclipse,所以如果我缺少一些相当明显的东西,我很抱歉。



我遇到的问题是我我试图在我的一个源文件中包含一个头文件,但它们位于我的项目目录中的不同文件夹中。我不知道我应该如何包容他们。我已经上传了一个图像,显示我想要包含的标题文件的问题。





如果有人可以告诉我'#include'语句我应该使用它们将是辉煌的。



谢谢!

解决方案

有几个不同的选择做这个工作。最简单的是将 #include 更改为

  #include.. /Statistics/Statistics.h

这将无需任何其他修改。但是,如果您移动任一文件,或以某种方式更改两者之间的相对路径,则将会中断。



或者,您可以将路径添加到统计信息文件夹到您的编译器的包含文件搜索路径。右键单击项目名称,选择属性 - > C / C ++构建 - >设置,然后找到您的编译器的包含文件路径选项。对于g ++,它是 -I< path / to / include / folder> 。添加这个将使 #include 语句正常工作。



与第二个类似的选项一个是将路径添加到包含搜索路径的 src 文件夹(而不是 Statistics 文件夹)中。在这种情况下,您必须将该声明更改为

   


I'm pretty new to C++ and Eclipse in general so I apologise if I'm missing something fairly obvious.

The problem I'm having is that I'm trying to include a header file in one of my source files but they're in different folders in my project directory. I have no idea how I should be including them. I've uploaded an image showing my problem with the header file I want to include highlighted.

If someone could tell me what '#include' statement I should be using them that would be brilliant.

Thanks!

解决方案

There are a couple of different options to make this work. Simplest is to change the #include to

#include "../Statistics/Statistics.h"

This will work without any other modifications. However, if you move either file, or somehow change the relative path between the two, this will break.

Alternately, you can add the path to the Statistics folder to your compiler's include file search path. Right click on the project name, select Properties -> C/C++ Build -> Settings and then find the includes files path option for your compiler. For g++, it is -I<path/to/include/folder>. Adding this will make the #include statement work as you currently have it.

A very similar option to the second one is to add the path to the src folder (instead of the Statistics folder) to the includes search path. In this case, you'll have to change the statement to

#include "Statistics/Statistics.h"

这篇关于Eclipse C ++包括我的源文件夹中的头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆