Eclipse C++ including header file from my source folder

怎甘沉沦 提交于 2019-11-30 01:16:13

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"

When you create subfolders in your src folder then each cpp file is compiled in that folder it is located in. Thus, any "" includes need to specify the relative path to get from that folder to another.

In your case, to get from inside the FileInOut folder you need to go back one level and then into the Statistics folder

eg

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

Another alternative is, if you are keeping your includes in your src directory, to add the src directory to the include path. Now when you include you need only specify the path from the src root.

eg.

#include "Statistics/Statistics.h"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!