How to define several include path in Makefile

C++IncludeMakefile

C++ Problem Overview


New to C++; Basic understanding of includes, libraries and the compile process. Did a few simple makefiles yet.

My current project involves using an informix DB api and i need to include header files in more than one nonstandard dirs. How to write that ? Havent found anything on the net, probably because i did not use good search terms

This is one way what i tried (not working). Just to show the makefile

LIB=-L/usr/informix/lib/c++
INC=-I/usr/informix/incl/c++ /opt/informix/incl/public

default:    main

main:   test.cpp
        gcc -Wall $(LIB) $(INC) -c test.cpp
        #gcc -Wall $(LIB) $(INC) -I/opt/informix/incl/public -c test.cpp

clean:
        rm -r test.o make.out

C++ Solutions


Solution 1 - C++

You have to prepend every directory with -I:

INC=-I/usr/informix/incl/c++ -I/opt/informix/incl/public

Solution 2 - C++

You need to use -I with each directory. But you can still delimit the directories with whitespace if you use (GNU) make's foreach:

INC=$(DIR1) $(DIR2) ...
INC_PARAMS=$(foreach d, $(INC), -I$d)

Solution 3 - C++

Make's substitutions feature is nice and helped me to write

%.i: src/%.c $(INCLUDE)
        gcc -E $(CPPFLAGS) $(INCLUDE:%=-I %) $< > $@

You might find this useful, because it asks make to check for changes in include folders too

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongroovehunterView Question on Stackoverflow
Solution 1 - C++Antoine PelisseView Answer on Stackoverflow
Solution 2 - C++wilhelmtellView Answer on Stackoverflow
Solution 3 - C++Vishwajith.KView Answer on Stackoverflow