QtCreator does not search sysroot/usr/include for header files even if the path was added to CMakeLists
-
I was cross compiling an application for Raspberry Pi with libgpiod. The cross compilation environment has been successfully set up according to this guid: https://wiki.qt.io/Cross-Compile_Qt_6_for_Raspberry_Pi. I have installed the libgpiod* libraries on RPi and rsync those files back to the host qt6pi/sysroot directory. The library was added to the project's CMakeList.txt file by:
add_library(libgpiod ~/qt6pi-sysroot/sysroot/usr/lib/aarch64-linux-gnu/libgpiod.so) target_include_directories(libgpiod INTERFACE ~/qt6pi-sysroot/sysroot/usr/include) target_link_libraries(testProj PRIVATE libgpiod)My problem is even if that target_include_directories was added, Qt Creator still complains that the header file <gpiod.h> was not found. And the weird thing is, when I moved the gpdiod.h header to other locations and accordingly change the above command, every thing works just fine. It seems like the sysroot/usr/include path was overwritten by /usr/include when Creator is searching for header files.
Could someone help me out about how to properly add a third party library to Qt project using CMake.
Thanks a lot!!! -
Hi!
I've been fiddling around with this issue and successfully reproduced your problem. Long story short, I found this CMake Wiki article and it helped quite a lot. The following CMake commands works for me:
add_library(libgpiod SHARED IMPORTED) set_target_properties(libgpiod PROPERTIES IMPORTED_LOCATION /home/uraihan/rpi-sysroot/usr/lib/aarch64-linux-gnu/libgpiod.so) target_include_directories(libgpiod INTERFACE /home/uraihan/rpi-sysroot/usr/include) target_link_libraries(demo_app PRIVATE libgpiod)When I tried this yesterday for the first time, Qt Creator also thrown a warning that the
gpiod.hfile is not found every time I'm declaring#include <gpiod.h>. The next day, I found that Qt Creator is no longer complaining about that anymore and I'm able to get the Qt Creator features for the library (autocomplete and all that stuff). So I'd suggest try restarting Qt Creator if you still get the warning after adding the external library toCMakeLists.txt.Hope it helps!
-
Thanks for your answer. Unfortunately, this did not work for me. It seems that the problem is about the path "~/qt6pi-sysroot/sysroot/usr/include" itself, since when I use the commands I have posted, everything works just fine with any other directories other than this one.
I worked this around by
target_include_directories(libgpiod INTERFACE ~/qt6pi-sysroot/sysroot/usr)
and then
#include <include/gpiod.h>