开发者

Does "make" know how to search sub-dirs for include files?

开发者 https://www.devze.com 2023-01-05 20:02 出处:网络
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\"

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.


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


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.


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).


everyone answered your question correctly. but something to consider when you get to setup your own source tree.... a leaf node should only look 2 places for headers, in its own directory or up the tree. once people start going across to peers and down the tree, the build system will get gnarly, but what also happens is folks with start using private interfaces when they should be using public interfaces

0

精彩评论

暂无评论...
验证码 换一张
取 消