I have a standard installed debian dev package which has an include file held e.g.
/usr/include/abcd.h
But I have an updated package compiled from source which has the include file as e.g.
/home/user01/include/abcd.h
How do I get either command line gcc or in a make file make sure it picks up the latter?
If I add either
gcc -I /home/user01/include
or
in the make file alter the includes line to have
INCLUDES = -I /home/user01/include
It appears to always take the one held in /usr/include first?
I had tried to keep it simple, but as per @MadScientist request here is more actual detail.
The following builds, no warnings or errors but the result of running indicates that it is using the old repo based version of mdbtools not the one I have compiled from source and utility programs within that run as expected with fixes. (on Debian 11)
gcc -g -O2 -DSQL -Wall -Werror -DUNIXODBC -o myTestMdb main.c -I /media/sdd02/src/mdbtools-deb11/include/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/include/cairo/ -I /usr/include/pango-1.0/ -I /usr/lib/x86_64-linux-gnu/gtk-2.0/include/ -I /usr/include/gdk-pixbuf-2.0/ -I /usr/include/atk-1.0/ -lmdb -lglib-2.0 -lmdbsql -DHAVE_GLIB
If I try (as suggested adding the -nostdinc)
gcc -g -O2 -DSQL -Wall -Werror -DUNIXODBC -o myTestMdb main.c -nostdinc -I /media/sdd02/src/mdbtools-deb11/include/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/include/cairo/ -I /usr/include/pango-1.0/ -I /usr/lib/x86_64-linux-gnu/gtk-2.0/include/ -I /usr/include/gdk-pixbuf-2.0/ -I /usr/include/atk-1.0/ -lmdb -lglib-2.0 -lmdbsql -DHAVE_GLIB
I get
main.c:20:10: fatal error: string.h: No such file or directory
20 | #include <string.h>
if I try
gcc -g -O2 -DSQL -Wall -Werror -DUNIXODBC -o myTestMdb main.c -nostdinc -I /media/sdd02/src/mdbtools-deb11/include/ -I /usr/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/include/cairo/ -I /usr/include/pango-1.0/ -I /usr/lib/x86_64-linux-gnu/gtk-2.0/include/ -I /usr/include/gdk-pixbuf-2.0/ -I /usr/include/atk-1.0/ -lmdb -lglib-2.0 -lmdbsql -DHAVE_GLIB
I get
/usr/include/string.h:26:10: fatal error: bits/libc-header-start.h: No such file or directory
26 | #include <bits/libc-header-start.h>
Likewise if I try to use make and have in the makdefile
INCLUDES = -I /media/sdd02/src/mdbtools-deb11/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/include/cairo/ -I /usr/include/pango-1.0/ -I /usr/lib/x86_64-linux-gnu/gtk-2.0/include/ -I /usr/include/gdk-pixbuf-2.0/ -I /usr/include/atk-1.0/ -I /media/sdd02/src/mdbtools/include/ -I /media/sdd02/src/mdbtools/include/
I get
/usr/include/mdbtools.h:37:10: fatal error: mdbfakeglib.h: No such file or directory
37 | #include <mdbfakeglib.h>
Note the /usr/include/mdbtools.h NOT the desired /media/sdd02/src/mdbtools-deb11/include/mdbtools.h which I have checked the folder that header file does exist there
so as per @G.M. suggestion I added the -H -P to the build this showed it was using the mdbtools.h (and other mdb related .h files) from where wanted. So the /usr/include/mdbtools.h was specific to a makefile issue. will leave that for now.
So now I think it is lib related I've only been using -lmdb -lmdbsql if I do a whereis I get the /usr/lib entries.
How do I make it use a different location I tried?
-L /media/sdd02/src/mdbtools-deb11/src/sql/ -L /media/sdd02/src/mdbtools-deb11/src/libmdb/ -lmdb -lmdbsql
or
-L /media/sdd02/src/mdbtools-deb11/src/sql/.libs -L /media/sdd02/src/mdbtools-deb11/src/libmdb/.libs -lmdb -lmdbsql
But it would still appear to use the /usr based ones from the output I get.
as per @G.M. tried adding -Wl -verbose but got
gcc: error: unrecognized command-line option ‘-Wl’; did you mean ‘-W’?
gcc: error: unrecognized command-line option ‘-verbose’; did you mean ‘--verbose’?
for reference gcc version is
gcc (Debian 10.2.1-6) 10.2.1 20210110
I reran with --verbose but I don't see any greater detail on where it is looking for mdbsql or libmdbsql.so from the -lmdbsql parameter which I hope should use from -L/media/sdd02/src/mdbtools-deb11/src/sql/.libs/ where it does exist but from output of built program I doubt.
Still have the makefile related issue to look into but the command line issue was my confusion on shared and static library.
I tried a "LD_LIBRARY_PATH=/media/sdd02/src/mdbtools-deb11/src/sql/.libs/:...etc " which did not work but an "export LD_LIBRARY_PATH="/media/sdd02/src/mdbtools-deb11/src/sql/.libs/: ... etc" did work as desired
question from:
https://stackoverflow.com/questions/66047047/makefile-include-path-hierarchy-and-lib-location