Linux Command Line Compilation

Hi, I am create a basic framework for the project I am going to be working on. My question is simply how to include header files not in the directory you are compiling from? My Hierarchy is as follows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-Main Directoy
    -My_Code_Folder
        -inc
            bitmap.hpp //the header file i am struggling to include
        -resources
        -src
            main.cpp
            bitmap.cpp
    -inc
        prg_core.hpp //includes all the header files stored in the prg folder
        -prg
            //assorted header files
    -lib
        -linux
            linux_library //has two libraries one for debug and one for release namely prgcore64 


The command I am typing is as follows, I am typing it whilst in the "My_Code_Folder" from the above directory in the terminal:
g++ -pedantic -I../inc -L../lib/linux src/main.cpp src/bitmap.cpp -l prgcore64 -o img_manip

I get the following errors:
src/main.cpp:2:22: error: bitmap.hpp: No such file or directory
src/main.cpp: In function ‘int main()’:
src/main.cpp:6: error: ‘hello’ was not declared in this scope
src/bitmap.cpp:1:26: error: inc/bitmap.hpp: No such file or directory


Here are the files I am using:

main.cpp
1
2
3
4
5
6
7
8
9
#include <prg_core.hpp>
#include <inc/bitmap.hpp>

int main()
{
	hello();

	return 0;
}


bitmap.cpp
1
2
3
4
5
6
7
8
9
10
#include <inc/bitmap.hpp>
#include <iostream>

using std::cout;
using std::endl;

void hello(void)
{
	cout << "Hello" << endl;
}


bitmap.hpp
1
2
3
4
#ifndef BITMAP_HPP
#define BITMAP_HPP
void hello(void);
#endif 


Its worth noting that the header file prg_core.hpp that is being is include is fine. I assume this is because i specify where to find it. I think I can get around the error by using #include "../inc/bitmap.hpp" but I think there is probably a better way using <> so I wouldn't mind understanding how it works a little better. Thanks in advance.
Last edited on
As you have it now you would have to include it like #include <bitmap.hpp> .

If you want to include it like #include <inc/bitmap.hpp> you should remove /inc from the path you pass to the compiler -I...


Last edited on
I don't think so because the path I pass to the compiler goes to the include folder for the library that i am using. I think that might be the issue I am having. My program is using on "inc" folder and the library is using its own one. So to do it the way you suggest I would have to have something like:

#include <../image_manipulation_ica/inc/bitmap.hpp> which is annoying :(
Topic archived. No new replies allowed.