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
Like that, you can set a default search path for the binary. Looks like you even already use -rpath in your makefile, but you specify the wrong path: LIBS = -L$(LIB) -lfuse -lsqlite3 -lkw_taglib -ltag_c -ltag -Wl,-rpath=. So the binary will search in the current directory for dyn-libraries.
$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.
The only way to include the header file is to treat the filename in the same way you treat a string. Makefiles are a UNIX thing, not a programming language thing Makefiles contain UNIX commands and will run them in a specified sequence.
The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: include filenames ... filenames can contain shell file name patterns.
You have to prepend every directory with -I
:
INC=-I/usr/informix/incl/c++ -I/opt/informix/incl/public
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With