# compiling problem

This is a discussion on compiling problem within the C++ Programming forums, part of the General Programming Boards category; Hi All. I just created a myproject folder. This folder contains two sub folders i.e. src and include to hold ...

1. ## compiling problem

Hi All.

I just created a myproject folder. This folder contains two sub folders i.e. src and include to hold .cpp and .h files.
I created a simple class in student.h file and defined a simple display function in student.cpp file.

Then I created another file inside src folder where I defined my main function i.e. mainfile.cpp and called display function.

The exact directory structure is this....

myproject
- include
-student.h
-src
-student.cpp
-mainfile.cpp

I compiled .h file. It compiled successfully. I compiled this from within include folder.

Then I tried to compile .cpp file using

c:\myproject\src\ g++ student.cpp

But it gave error as it could not find student.h file. I had included student.h file within the student.cpp file.

Can any one help about how can I compile .cpp file successfully.

2. The compiler knows how to find your files how? You should specify the path to the headers on the command line.

3. Originally Posted by MacGyver
The compiler knows how to find your files how? You should specify the path to the headers on the command line.
Do you want to say that

I should give

Is above line correct.

But if I use 5 header files then do I need to give the path of all header files like this.....

Is not any other way...

4. Something like this:

Code:
`g++ -IC:\myproject\include student.cpp`
Note the space between the path and the .cpp file you're compiling.

5. Originally Posted by MacGyver
Something like this:

Code:
`g++ -IC:\myproject\include student.cpp`
Note the space between the path and the .cpp file you're compiling.
THANKS