[question] How to make compiler ignore system paths?
Hello,
In a CentOS 7 system, I'm trying to build libpng which depends on zlib. I have zlib 1.1.1c installed as a system-wide library but I want to use Conan's zlib 1.1.1w. It seems that GCC is using the zlib.h in /usr/include instead of the one in Conan cache. I found out that by doing in generate() callback (I can't copy & paste text from the remote desktop, sorry, only screen capture the local terminal):
solves the issue, however, I'd like to know whether there is a compiler-agnostic way in Conan API to do so.
thanks,
PC
Have you read the CONTRIBUTING guide?
- [X] I've read the CONTRIBUTING guide
Hi @PauloCarvalhoRJ
Thanks for your question.
It seems that GCC is using the zlib.h in /usr/include instead of the one in Conan cache. I found out that by doing in generate() callback (I can't copy & paste text from the remote desktop, sorry, only screen capture the local terminal):
This is generally a function not only of the compiler, but also the build system, the specific platform, the build scripts, etc. In general the system includes will be last in the include order, so if things are ok, the Conan dependency should be found first.
If not, it might be necessary a reproducible case, do you have a docker image or something that could reproduce this? Thanks.
On Linux in general, if you wish to use zlib from Conan, the relevant integrations will ensure that the relevant flag is passed to the compiler such that it finds zlib from Conan, before it even looks in the system
Are you sure you are not missing something in your consumer CMakeLists? such like
find_package(ZLIB REQUIRED)
target_link_libraries(your_target PRIVATE ZLIB::ZLIB)
Hi, @memsharded and @jcar87,
Thank you for the insights. Now that you mentioned search order, instead of using -nostdinc[++], which caused other problems, I added CMAKE_CXX_FLAGS=-I/... and CMAKE_C_FLAGS=-I/... in the generate() callback of the recipe. This solved the issue (for VS, the include directory flag name is /I).
Are you sure you are not missing something in your consumer CMakeLists? such like
find_package(ZLIB REQUIRED)
target_link_libraries(your_target PRIVATE ZLIB::ZLIB)
My libpng's CMakeLists.txt (the consumer package) has these, but I still got preprocessor check errors like #if PNG_ZLIB_VERSION != ZLIB_VERSION. This check is performed in libpng code (I don't recall the specific source file right now). Anyway, judging by their hex value contents, the former define is correctly taken during build from Conan's zlib.h but the later is being taken from /usr/include/zlib.h somehow. Adding the -I solved this because it takes precedence over system includes like mentioned by @memsharded .
best,
PC