tags:

views:

72

answers:

3

Hello

This is a question for experienced C/C++ developpers.

I have zero knowledge of compiling C programs with "make", and need to modify an existing application, ie. change its "config" and "makefile" files.

The .h files that the application needs are not located in a single-level directory, but rather, they are spread in multiple sub-directories.

In order for cc to find all the required include files, can I just add a single "-I" switch to point cc to the top-level directory and expect it to search all sub-dirs recursively, or must I add several "-I" switches to list all the sub-dirs explicitely, eg. -I/usr/src/myapp/includes/1 -I/usr/src/myapp/includes/2, etc.?

Thank you.

+3  A: 

This question appears to be about the C compiler driver, rather than make. Assuming you are using GCC, then you need to list each directory you want searched:

gcc -I/foo -I/foo/bar myprog.c
anon
Thanks guys, this is what I suspected ;-) I'll have to add all the sub-dirs with -I, then.
+1  A: 

This is actually a compiler switch, unrelated to make itself.

The compiler will search for include files in the built-in system dirs, and then in the paths you provide with the -I switch. However, no automatic sub-directory traversal is made.

For example, if you have

#include "my/path/to/file.h"

and you give -I a/directory as a parameter, the compiler will look for a/directory/my/path/to/file.h.

adamk
A: 

If the makefiles are written in the usual way, the line that invokes the compiler will use a couple of variables that allow you to customize the details, e.g. not

gcc (...)

but

$(CC) $(CFLAGS) (...)

and if this is the case, and you're lucky, you don't even need to edit any of the makefiles; instead you can invoke make like this

make CFLAGS='-I /absolute-path/to/wherever'

to incorporate your special options into the compiler invocation.

Also check whether the Makefiles aren't generated by something else (usually, a script in the top directory called

configure

which will have options of its own to control what goes into them).

reinierpost