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

Add wiringPi to cross compile



  • Hi,

    I configured environment for cross compile for my RaspberryPi 3B. I created project which use wiringPi library.
    My pro file:

    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    INCLUDEPATH += /home/john/raspi/sysroot/usr/include/
    
    LIBS += -L"/home/john/raspi/sysroot/usr/lib"
    LIBS += -lwiringPi
    
    HEADERS +=
           wiringPi.h
    
    SOURCES += \
            main.cpp
    
    target.path = home/pi/
    #QtProjects/testRpi
    INSTALLS += target
    
    # Default rules for deployment.
    #qnx: target.path = /tmp/$${TARGET}/bin
    #else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    My main.cpp

    #include <QCoreApplication>
    #include <QDebug>
    #include <wiringPi.h>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        wiringPiSetup();
    
        return a.exec();
    }
    

    But when I try build project i get error:
    error: use of undeclared identifier 'wiringPiSetup'

    What can I do to fix that?


  • Lifetime Qt Champion

    @Creatorczyk said in Add wiringPi to cross compile:

    #include <wiringPi.h>

    So, it does not complain about this header (it is found?)?
    Can you check the content of that header file?



  • Hi there!

    I think in .pro file you have to setup all include paths and library paths in relation to original root path on device and have correct setup of kit and sysroot path in "Kit" option on Qt Creator side.

    In my project.pro file i have added only:

    LIBS += -L/usr/local/lib/libwiringPi.so -lwiringPi
    

    When you have correct kit setup (with sysroot) in Qt Creator options, Qt will find header file by himself. If you want to check full pro file take look on my gitlab page: https://gitlab.com/GoRo3/rpibuttons/-/blob/master/Rpi3_Buttons.pro

    Best regards!
    GoRo3



  • @GoRo3
    But the OP is not reporting that the included file is not found (else he would undoubtedly have said so...), he is reporting "use of undeclared identifier"....



  • Try to add the *Dev version.

    LIBS += -L"path_to_raspi_sysroot"/usr/lib/ -lwiringPiDev

    It seems that your Lib path does not refer to the raspi sysroot.

    /usr/local/lib is a path on your host if you cross compile.



  • @Creatorczyk said in Add wiringPi to cross compile:

    I configured environment for cross compile for my RaspberryPi 3B. I created project which use wiringPi library.

    Have you cross-compiled the wiringPi library?
    or have you installed directly in your RPi device?

    One way or the other, are you positive that the wiringPi library and header files are synchronized into your sysroot folder in the host machine?

    Having a Yes for answer to that question, please check that file wiringPi.h is available in the path stated in your INCLUDEPATH setting from your .pro file.



  • I checked your suggestions and I was unable to solve the problem.

    @jsulm @JonB
    The library "libwiringPi.so" exist in path:
    /home/john/raspi/sysroot/usr/lib on the PC
    /usr/lib on the RPI

    and file "wiringPi.h" exist in path:
    /home/john/raspi/sysroot/usr/include on the PC
    /usr/include on the RPI

    Maybe it is important, but while building the application I don't get any errors in the pro file. (I made them especially for the test and it did not detect)

    @GoRo3 I tried and it did not help. But my libwiringPi.so is in the path /usr/lib on the RPi, so i try:

    INCLUDEPATH += /home/john/raspi/sysroot/usr/include/
    LIBS += -L/usr/lib/libwiringPi.so -lwiringPi

    I set up everything just like in this tutorial:
    https://mechatronicsblog.com/cross-compile-and-deploy-qt-5-12-for-raspberry-pi/

    I have WARNING like
    "/home/john/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc" is used by qmake, but
    "/home/john/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/bin/gcc" is configured in the kit.
    Please update your kit (RaspberryPi3) or choose a mkspec for qmake that matches your target environment better.

    But application for "Hello World" works

    @ad1170 your solution doesn't work.
    INCLUDEPATH += /home/john/raspi/sysroot/usr/include/
    LIBS += -L/home/pi/usr/lib/ -lwiringPiDev



  • @Creatorczyk said in Add wiringPi to cross compile:

    But when I try build project i get error:
    error: use of undeclared identifier 'wiringPiSetup'

    If this is indeed the error message you get when trying to compile your main.cpp which has

    #include <wiringPi.h>
    ...
    wiringPiSetup();
    

    and there are not other errors, then I don't understand how the half the questions about libraries or whether the included file exists or not are relevant....


Log in to reply