eDeviser
eDeviser

Reputation: 1871

How to use GCC's I-flag to include multiple folders?

Normally I use GCC's I-flag to include folders in this way:

gcc main.c -IfolderA -IfolderB

Well I need to reorganize my makefiels structure and I'm thinking about to have an environment variable which is defined as this:

INCLUDES="folderA folderB"

How could I use GCC's I-flag to include both folders?

I thought about something (but it does not work) like this:

gcc main.c -I($(INCLUDES))

Upvotes: 1

Views: 1707

Answers (2)

user2371524
user2371524

Reputation:

You could also use the addprefix function -- although it's designed to work on filenames, it can still be used here:

gcc main.c $(addprefix -I,$(INCLUDES))

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409442

You need to add the -I flag to all the "elements" of your INCLUDES variable. Perhaps through something like this:

gcc main.c $(foreach dir,$(INCLUDES),-I$(dir))

The foreach function.

Upvotes: 2

Related Questions