[MSYS2/GCC-TDM] Compiler not finding headers in /usr/local/include

I hope it's okay to post this here. I'm working on Windows computer but using the Unix-like environment MSYS2 (https://sourceforge.net/projects/msys2\).

My problem is that I can't get the compiler to find headers located in /usr/local/include. I am trying to compile libpng which wants the header "zlib.h":

$ ../configure --disable-static LDFLAGS="-L/usr/local/lib" CXXLAGS="-I/usr/local/include"
...
...
...
checking for zlibVersion in -lz... yes
...
...
...

$ make
rm -f pnglibconf.c pnglibconf.tf[45]
gawk -f ../scripts/options.awk out=pnglibconf.tf4 version=search\
    ../pngconf.h ../scripts/pnglibconf.dfa\
    ../pngusr.dfa  1>&2
gawk -f ../scripts/options.awk out=pnglibconf.tf5 pnglibconf.tf4 1>&2
rm pnglibconf.tf4
mv pnglibconf.tf5 pnglibconf.c
rm -f pnglibconf.out pnglibconf.tf[12]
test -d scripts || mkdir scripts || test -d scripts
gcc -E -DHAVE_CONFIG_H -I. -I.. \
     -DPNGLIB_LIBNAME='PNG16_0' -DPNGLIB_VERSION='1.6.16' -DSYMBOL_PREFIX='' -DPNG_NO_USE_READ_MACROS -DPNG_BUILDING_SYMBOL_TABLE  pnglibconf.c > pnglibconf.tf1
pnglibconf.c:33:19: fatal error: zlib.h: No such file or directory
 # include <zlib.h>
                   ^
compilation terminated.
Makefile:2143: recipe for target 'pnglibconf.out' failed
make: *** [pnglibconf.out] Error 1

$ ls /usr/local/include | grep zlib
zlib.h

I have no clue why it's not finding it.

[s]```text
$ whereis ld
ld: /mingw64tdm/bin/ld.exe

$ ld --verbose | grep SEARCH
SEARCH_DIR("/mingw64tdm/x86_64-w64-mingw32/lib"); SEARCH_DIR("/mingw64tdm/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");



Anyone have any ideas?

--- Edit ---

Sorry, that part about the linker was not necessary.

--- Edit ---

Ugh! I was using the wrong variable. "CXXFLAGS" should have been "CPPFLAGS".
1 Like

Thanks for posting the solution. IT may help someone else.