How to set up RPi WiringPi library and other libs for Qt cross-compile



  • In an old topic I found this interesting reply from @SGaist (post/381375):

    snip ... install the development package on the RPi and sync the sysroot you use when cross-compiling your application ...

    I got cross-compiling for RPi2 & RPi3 to work for Qt 5.10.1 using the guide in wiki.qt.io/RaspberryPi2EGLFS and have then been trying to get the wirinpi lib to function too. I have tried to sync the needed stuff back to the host from RPi using rsync but haven't got things to work. Can someone please clarify what to do for the sysroot folder (if anything) to get all the wiringpi libraries in proper places. This is a list of the wiringpi related stuff on RPi:

    pi@rpi2:/ $ sudo find -name wiri

    ./home/pi/sysroot/usr/lib/libwiringPiDev.so
    ./home/pi/sysroot/usr/lib/libwiringPi.so
    ./home/pi/wiringPi
    ./home/pi/wiringPi/wiringPiD
    ./home/pi/wiringPi/wiringPiD/wiringpid.c
    ./home/pi/wiringPi/debian/libwiringpi2.shlibs
    ./home/pi/wiringPi/debian/wiringpi.install
    ./home/pi/wiringPi/debian/libwiringpi2.install
    ./home/pi/wiringPi/debian/libwiringpi-dev.install
    ./home/pi/wiringPi/debian/wiringpi.dirs
    ./home/pi/wiringPi/debian/libwiringpi-dev.dirs
    ./home/pi/wiringPi/debian-template/wiringPi
    ./home/pi/wiringPi/devLib/libwiringPiDev.so.2.46
    ./home/pi/wiringPi/wiringPi
    ./home/pi/wiringPi/wiringPi/wiringPiSPI.o
    ./home/pi/wiringPi/wiringPi/wiringShift.c
    ./home/pi/wiringPi/wiringPi/wiringPiSPI.h
    ./home/pi/wiringPi/wiringPi/wiringSerial.c
    ./home/pi/wiringPi/wiringPi/libwiringPi.so.2.46
    ./home/pi/wiringPi/wiringPi/wiringPi.c
    ./home/pi/wiringPi/wiringPi/wiringPiI2C.h
    ./home/pi/wiringPi/wiringPi/wiringSerial.h
    ./home/pi/wiringPi/wiringPi/wiringPiI2C.c
    ./home/pi/wiringPi/wiringPi/wiringPiSPI.c
    ./home/pi/wiringPi/wiringPi/wiringSerial.o
    ./home/pi/wiringPi/wiringPi/wiringShift.h
    ./home/pi/wiringPi/wiringPi/wiringPi.o
    ./home/pi/wiringPi/wiringPi/wiringPiI2C.o
    ./home/pi/wiringPi/wiringPi/wiringShift.o
    ./home/pi/wiringPi/wiringPi/wiringPi.h
    ./usr/local/lib/libwiringPiDev.so
    ./usr/local/lib/libwiringPi.so.2.46
    ./usr/local/lib/libwiringPi.so
    ./usr/local/lib/libwiringPiDev.so.2.46
    ./usr/local/include/wiringPiSPI.h
    ./usr/local/include/wiringPiI2C.h
    ./usr/local/include/wiringSerial.h
    ./usr/local/include/wiringShift.h
    ./usr/local/include/wiringPi.h
    ./usr/lib/libwiringPiDev.so
    ./usr/lib/libwiringPi.so

    This is what I currently have in sysroot:

    ri@PC:~/raspi2 $ sudo find -name wiri

    ./sysroot/usr/include/wiringPi.h
    ./sysroot/usr/include/wiringShift.h
    ./sysroot/usr/include/wiringPiI2C.h
    ./sysroot/usr/include/wiringSerial.h
    ./sysroot/usr/include/libwiringPi.so
    ./sysroot/usr/include/libwiringPiDev.so
    ./sysroot/usr/include/wiringPiSPI.h
    ./sysroot/usr/lib/libwiringPi.so
    ./sysroot/usr/lib/libwiringPiDev.so

    This is what I have in .pro

    TEMPLATE = app
    CONFIG += console
    ///EDIT: Removed wrong tested compiler option
    CONFIG -= app_bundle
    CONFIG -= qt

    INCLUDEPATH += /home/ri/raspi2/sysroot/usr/lib/
    INCLUDEPATH += /home/ri/raspi2/sysroot/usr/include/

    LIBS += -L"/home/ri/raspi2/sysroot/usr/include" -libwiringPi.so
    LIBS += -L"/home/ri/raspi2/sysroot/usr/include" -libwiringPiDev.so
    LIBS += -lwiringPi -lwiringPiDev

    HEADERS +=
    wiringpi.h

    SOURCES +=
    main.c

    target.path = /home/pi/wire
    INSTALLS += target

    The compiler does not find the libraries except wirinpi.h and all files in RPi don't seem to be synced back to my host(but do they even need to be?) There probably are many things wrong but the first thing I would like to know is if the sysroot folder structure should somehow be revised to match what is in RPi for wiringpi and how.

    EDIT: This the sysroot folder structure:

    mkdir sysroot sysroot/usr sysroot/opt

    I ran these again after I instlled wiringpi on RPi

    rsync -avz pi@raspberrypi.local:/lib sysroot
    rsync -avz pi@raspberrypi.local:/usr/include sysroot/usr
    rsync -avz pi@raspberrypi.local:/usr/lib sysroot/usr
    rsync -avz pi@raspberrypi.local:/opt/vc sysroot/opt

    Thanx

    PS. If I get this to work I also need to be able to use RPi's serial interface to read analog data from an Arduino which should be connected via USB cable (serial). That probably needs some libraries too if not already in place.



  • @robopoulos couple of things I can see quickly:

    1. You have Wiring Pi installed in a bunch of different locations in your RPi device. I understand that you should have it installed under /usr/lib (.so) and /usr/include (.h) only. Those are the locations that you then sync
    rsync -avz pi@raspberrypi.local:/usr/include sysroot/usr
    rsync -avz pi@raspberrypi.local:/usr/lib sysroot/usr
    
    1. You don't need both wiringPi and wiringPiDev shared libraries unless you're using the Gertboard, MaxDetect, etc. see here

    NOTE: To compile programs with wiringPi, you need to add:
    -lwiringPi
    to your compile line(s) To use the Gertboard, MaxDetect, etc.
    code (the devLib), you need to also add:
    -lwiringPiDev
    to your compile line(s).

    so this fragment from your .pro

    INCLUDEPATH += /home/ri/raspi2/sysroot/usr/lib/
    INCLUDEPATH += /home/ri/raspi2/sysroot/usr/include/
    
    LIBS += -L"/home/ri/raspi2/sysroot/usr/include" -libwiringPi.so
    LIBS += -L"/home/ri/raspi2/sysroot/usr/include" -libwiringPiDev.so
    LIBS += -lwiringPi -lwiringPiDev
    

    should change into:

    INCLUDEPATH += /home/ri/raspi2/sysroot/usr/include/
    
    LIBS += -L"/home/ri/raspi2/sysroot/usr/lib"
    LIBS += -lwiringPi
    

    PS. If I get this to work I also need to be able to use RPi's serial interface

    You may want to take a look at the simplified serial port handling library included in WiringPi.



  • Thanks! As seen from the listings the libs were already in the proper folders. Then after you fixed the .pro the -lwiringPi still wasn't found so I inspected the files with Filezilla on RPi and it revealed that the .so files synced to the host were just but links(!) pointing to the to the original wiringPi build folder. I copied the actual .so files from the original build file to the host and now it works!

    THANX!

    I mark this as solved. Perhaps I start a new topic if I need help for the serial Arduino connection.



  • @robopoulos said in How to set up RPi WiringPi library and other libs for Qt cross-compile:

    Glad you solved your issue.

    Perhaps I start a new topic if I need help for the serial Arduino connection.

    Yes please. Keep the forum tidy, one subject per post so other users can find help easier


Log in to reply