Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

could not add wiringPi to Qt after cross compiling



  • Hello,

    I cross compiled Qt for raspberry pi 4. I am working on a lite version of OS
    and before cross compiling I didn't check if wiring pi was installed or not ..

    Now that I need these library to start using GIOP pins, I couldn't add it.
    so this is what I did to install it:

    on my raspberry pi :

    sudo apt update
    sudo apt full-upgrade
    sudo apt-get install wiringpi
    cd
    mkdir wiringPi
    cd wiringPi
    pi@raspberrypi:~/wiringPi $ wget https://project-downloads.drogon.net/wiringpi-latest.deb
    sudo dpkg -i wiringpi-latest.deb
    

    after that on my ubuntu and in my working folder (the one that contains the source code of my Qt application ) I added the libwiringPi.so
    scp pi@192.168.1.31:/usr/lib/libwiringPi.so .

    after that I tried to add it to my project as an external library
    so now my .pro file looks like this

    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /home/pi/$${TARGET}
    !isEmpty(target.path): INSTALLS += target
    
    DISTFILES +=
    
    HEADERS += \
        contacteur.h \
        capteur.h
    
    unix:!macx: LIBS += -L$$PWD/./ -lwiringPi
    
    INCLUDEPATH += $$PWD/.
    DEPENDPATH += $$PWD/.
    

    and when including #include<wiringPi.h>

    an error shows up no such file or directory

    is there any way to fix this or should I do the cross compilation again ?

    Thank you for helping



  • Typically, in order to use a *so shared library, you need both the binary library itself (the *so) and the human-readable header files *h.

    In the build configuration, you need to "point to" the location of both those:

    INCLUDEPATH += $${dirforheaders}         # DO NOT COPY THIS LITERALLY. Adjust for your use.
    LIBS += -L$$shadowed($$PWD) -lwiringPi  # DO NOT COPY THIS LITERALLY. Adjust for your use.
    

    There is no technology that allows the build process (the "build toolchain") to extrapolate from the *so where to find the corresponding headers.

    So you almost always need to adjust you INCLUDEPATH and your LIBS.

    You might be thinking of an exceptional case, like... "well how is it that I use zlib.h or locale.h or other well-known header files without figuring out the relevant INCLUDEPATH?" ... This would be a good question! This is due to certain paths being automatically searched.

    The following are common automatically-searched paths:

    /usr/local/include
    /usr/include

    More info: https://gcc.gnu.org/onlinedocs/gcc-4.9.4/cpp/Search-Path.html


    UPDATE: @Pablo-J-Rogina is correct to also mention the particular specific concerns in a cross-compiling environment. I admit that even though "cross compile" is mentioned immediately at the top of the question, I neglected to consider those particulars.

    At minute 23:20 of the video tutorial the video author switches the target to Arm ABI, and that is when he made the "no such file or directory" go away on his machine. Suggesting that on the video author's machine, the header was present in some directory such as "${MY_CROSSCOMPILE_TOOLS}/arm_abi/sysroot/usr/include/"


  • Lifetime Qt Champion

    @amina said in could not add wiringPi to Qt after cross compiling:

    is there any way to fix this or should I do the cross compilation again ?

    Yes: add the folder containing WiringPi header files to INCLUDEPATH



  • @jsulm I tried it and I got the same error

    INCLUDEPATH += /home/amina/Desktop/test_v1
    

  • Lifetime Qt Champion

    @amina
    Hi
    If you look in
    /home/amina/Desktop/test_v1
    is the .h files in that folder ?
    And not in a sub folder, like include ?



  • @mrjj the libwiringPi.so in test_v1
    wiringPi.png



  • (Unless I am missing it and my eyes are too slow...) Your screenshot shows that the '*so' is in the test_v1 folder, but INCLUDEPATH is not for finding the '*so', it is for finding the header file. So as @mrjj asked: what folder has as plain-text file named "wiringPi.h" inside it? That is the folder to add to INCLUDPATH.

    If you can find a copy of this book (either an online PDF copy or any other), then I highly recommend it to all people just getting started in either C or C++. It's less than 100 pages and full of compilation examples that precisely clarify what header files are and what their relationship to '*so' files is.

    Also, while the book title says "GCC", the same principles hold one-for-one when using Clang.

    (Book: An Introduction to GCC, by Brian Gough)



  • Typically, in order to use a *so shared library, you need both the binary library itself (the *so) and the human-readable header files *h.

    In the build configuration, you need to "point to" the location of both those:

    INCLUDEPATH += $${dirforheaders}         # DO NOT COPY THIS LITERALLY. Adjust for your use.
    LIBS += -L$$shadowed($$PWD) -lwiringPi  # DO NOT COPY THIS LITERALLY. Adjust for your use.
    

    There is no technology that allows the build process (the "build toolchain") to extrapolate from the *so where to find the corresponding headers.

    So you almost always need to adjust you INCLUDEPATH and your LIBS.

    You might be thinking of an exceptional case, like... "well how is it that I use zlib.h or locale.h or other well-known header files without figuring out the relevant INCLUDEPATH?" ... This would be a good question! This is due to certain paths being automatically searched.

    The following are common automatically-searched paths:

    /usr/local/include
    /usr/include

    More info: https://gcc.gnu.org/onlinedocs/gcc-4.9.4/cpp/Search-Path.html


    UPDATE: @Pablo-J-Rogina is correct to also mention the particular specific concerns in a cross-compiling environment. I admit that even though "cross compile" is mentioned immediately at the top of the question, I neglected to consider those particulars.

    At minute 23:20 of the video tutorial the video author switches the target to Arm ABI, and that is when he made the "no such file or directory" go away on his machine. Suggesting that on the video author's machine, the header was present in some directory such as "${MY_CROSSCOMPILE_TOOLS}/arm_abi/sysroot/usr/include/"



  • @KH-219Design
    Thank you for clarifying! it seems quite obvious

    https://www.youtube.com/watch?v=_R_NA-vubKw
    I was following this tutorial (minute 21:48) he is adding this library and he just copied the .so file
    but I think that wiringPi is installed on his raspberry before he cross compiled Qt so when he created the sysroot directory it contains already the wiringPi.h but the problem is when he added the external library he putted in the INCULUDEPATH the path of his working directory and not the sysroot/usr/include but it worked for him.
    I just copied the /usr/include/wiringPi.h in my working folder and now it is working.
    Thank you !



  • @amina just in case, when you're working with a cross-compile environment and you later on add a library (.so + .h files) to your device, you're supposed to synchronize again, that is, making those files from the device copied into your sysroot in your host machine.



  • I'm glad it's working now.

    I noticed in the description of the YouTube video that the video author links to a GitHub repo, and indeed the GitHub repo shows no sign of adding any INCLUDEPATH other than $$PWD.

    You might be able to communicate with the author on GitHub by opening an issue on that repo. It seems unnecessary now. But if anything else comes up you might entertain the idea.



  • @Pablo-J-Rogina
    thank you, I didn't know that. I just need to synchronize the /usr/include and /usr/lib or all the sysroot?

    rsync -avz pi@192.168.1.31:/usr/include sysroot/usr
    rsync -avz pi@192.168.1.31:/usr/lib sysroot/usr
    


  • @KH-219Design said in could not add wiringPi to Qt after cross compiling:

    You might be able to communicate with the author on GitHub by opening an issue on that repo. It seems unnecessary now. But if anything else comes up you might entertain the idea.

    okay i will consider it next time, thank you



  • @amina said in could not add wiringPi to Qt after cross compiling:

    I just need to synchronize the /usr/include and /usr/lib or all the sysroot?

    It depends on the changes you do, and if you know exactly what folders were modified.
    Some people perform the sync for the whole sysroot just in case.