Nicox11
Nicox11

Reputation: 106

Build makefile with source and header in separate folder

I'm trying to build a Makefile with separate folder for my sources and my headers. I have a the root of my project that contain an include folder that holds my .hpp files, and a source folder that holds my .cpp files. How can i build the Makefile that it builds all the .cpp with the respective .hpp files ?

How to create the program output in a folder called build ?

Thank you in advance

Upvotes: 0

Views: 886

Answers (2)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136515

I'm trying to build a Makefile with separate folder for my sources and my headers.

An alternative way would be to have your headers in the same directory as your .cpp files. And in that top level include folder you can put symbolic links to the headers.

Upvotes: 0

Russ Schultz
Russ Schultz

Reputation: 2689

Make is so diverse, there's a LOT of ways to do this, but the end result is -I<your hpp path> (or -J) needs to be passed to the compiler to tell it additional include paths to search when resolving #include

The path needs to relative to the invocation of the rule directory, or relative to the file (I'm pretty sure the compiler searches both).

A lot of makefiles use CPPOPTS and CCOPTS or some variant of that in the makefile to pass extra options to the C or CPP compiler. Try adding:

CPPOPTS += -I..\include

To your makefile (assuming you've segregated your source and include files that way).

Again, this is ALL dependent on your makefile.

Upvotes: 1

Related Questions