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

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

问题描述

我对C ++和Eclipse一般都很新鲜,所以如果我错过了一些相当明显的东西,我道歉。



我遇到的问题是, '试图包括一个头文件在我的源文件,但他们在我的项目目录中的不同的文件夹。我不知道我应该如何包括他们。我已上传一个图片,显示我要在其中突出显示的标题文件的问题。





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



谢谢!

解决方案

使这项工作。最简单的是将 #include 更改为

  #include /Statistics/Statistics.h

这将在没有任何其他修改的情况下工作。



或者,您可以将路径添加到<$ c $

c> Statistics 文件夹添加到编译器的include文件搜索路径。右键单击项目名称,选择属性 - > C / C ++构建 - >设置,然后找到包含文件路径选项的编译器。对于g ++,它是 -I 。添加此选项将使 #include 语句按照您当前的方式工作。



一个是将 src 文件夹(而不是 Statistics 文件夹)的路径添加到包含搜索路径。在这种情况下,您必须将语句更改为

  #includeStatistics / Statistics.h


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天全站免登陆