Eclipse C++ 包括来自我的源文件夹的头文件

Eclipse C++ including header file from my source folder(Eclipse C++ 包括来自我的源文件夹的头文件)
本文介绍了Eclipse C++ 包括来自我的源文件夹的头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

总的来说,我对 C++ 和 Eclipse 还很陌生,所以如果我遗漏了一些相当明显的东西,我深表歉意.

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.

如果有人能告诉我应该使用什么#include"语句,那就太好了.

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

谢谢!

推荐答案

有几个不同的选项可以完成这项工作.最简单的是将 #include 改为

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.

或者,您可以将 Statistics 文件夹的路径添加到编译器的包含文件搜索路径中.右键单击项目名称,选择 Properties -> C/C++ Build -> Settings,然后找到编译器的包含文件路径选项.对于 g++,它是 -I.添加这将使 #include 语句像您当前拥有的那样工作.

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.

与第二个非常相似的选项是将 src 文件夹的路径(而不是 Statistics 文件夹)添加到包含搜索路径.在这种情况下,您必须将语句更改为

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++ 包括来自我的源文件夹的头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Eclipse C/C++ (CDT) import files into project - header file not found - include path(Eclipse C/C++ (CDT) 将文件导入项目 - 找不到头文件 - 包含路径)
How to implement RecyclerView with section header depending on category?(如何根据类别实现带有节标题的 RecyclerView?)
How to generate JNI header file in Eclipse(如何在 Eclipse 中生成 JNI 头文件)
Setting a custom HTTP header dynamically with Spring-WS client(使用 Spring-WS 客户端动态设置自定义 HTTP 标头)
Could you technically call the string[] anything in the main method?(从技术上讲,您可以在 main 方法中调用 string[] 吗?)
What is the proper way of setting headers in a URLConnection?(在 URLConnection 中设置标头的正确方法是什么?)