BadProgrammer99 BadProgrammer99 - 6 months ago 24
C++ Question

C++ includes acting funny Eclipse

I'm trying to write a neural net in C++, and in one of the header files I'm trying to write, there's an issue with the an include at the top. When I double click the include in Eclipse's outline for the file, it takes me to the write one, so Eclipse knows it's there, but the compiler keeps complaining it isn't. The directory looks something like this (I cut out all files that had nothing to do with the problem):


The Layers.h file code is below:

#include <vector>
#include "../src/Neurons/Neuron.h"

class Layer{
std::vector<Neuron> layer;
Layer(Neuron a, int n){
layer = std::vector<Neuron>(n);
for(int i = 0;i<n;i++){
layer[i] = a;
virtual std::vector<double> fire(std::vector<double>);
virtual std::vector<double> fire();
virtual std::vector<double> derivative(std::vector<double>);
virtual std::vector<double> derivative();
virtual ~Layer(){}

#endif /* LAYERS_LAYER_H_ */

and the line with #include "../src/Neurons/Neuron.h" gives the error

In file included from ..\src\Layers\Layer.cpp:7:0:
..\src\Layers\Layer.h:11:10: fatal error: ../src/Neurons/Neuron.h: No such file or directory
#include "../src/Neurons/Neuron.h"
compilation terminated.

I've been able to include the file in main.cpp and it works fine.

Answer Source

#include "../src/Neurons/Neuron.h" tells compiler to go up one level in hierarchy of directories relative to this file location. So ../ would be already inside of src and there is no need to add /src. So your include should look like:

#include "../Neurons/Neuron.h"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download