Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    QtonPi
    4
    11
    4973
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      robopoulos last edited by robopoulos

      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.

      Pablo J. Rogina 1 Reply Last reply Reply Quote 0
      • Pablo J. Rogina
        Pablo J. Rogina @robopoulos last edited by

        @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.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 3
        • R
          robopoulos last edited by

          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.

          Pablo J. Rogina 1 Reply Last reply Reply Quote 0
          • Pablo J. Rogina
            Pablo J. Rogina @robopoulos last edited by

            @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

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 2
            • B
              barath.19.2 last edited by

              @Pablo J. Rogina I was setting up my ubuntu for cross compilation when including the wiringPi.h header file in the .pro file like this

              INCLUDEPATH += /usr/local/include

              LIBS += -L"/usr/local/lib" -lwiringpi

              i got an error
              Screenshot from 2019-12-06 13-12-31.png

              can you please help me out

              jsulm 1 Reply Last reply Reply Quote 0
              • jsulm
                jsulm Lifetime Qt Champion @barath.19.2 last edited by jsulm

                @barath-19-2 Did you install the lib in /usr/local/lib? Is the lib there?
                Also, what is the exact file name of the lib?
                And it looks like you're not doing cross-compalation?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                B 2 Replies Last reply Reply Quote 1
                • B
                  barath.19.2 @jsulm last edited by

                  @jsulm
                  here is a screen-shot of the directory
                  Screenshot from 2019-12-06 13-22-05.png
                  and this is the header file i downloaded from the unofficial git hub mirror because official was unavailable

                  Screenshot from 2019-12-06 13-28-02.png
                  after doing ./build i did same told in the previous conversations of this topic to do it the header file got included the header files and functions come in auto-complete when codding but this error pops up while building
                  Screenshot from 2019-12-06 13-12-31.png

                  1 Reply Last reply Reply Quote 0
                  • B
                    barath.19.2 @jsulm last edited by

                    @jsulm I used flash boot to QT Device to flash my SD card for Raspberry Pi to upload their Boot to Qt into SD card as showed in qthelp://io.qt.b2qt.598/b2qt/qtee-preparing-hardware-rasberrypi.html#2-installing-boot-to-qt-software-stack after this I thought i could cross-compile but when ran the example in it. It ran with no errors

                    jsulm 1 Reply Last reply Reply Quote 0
                    • jsulm
                      jsulm Lifetime Qt Champion @barath.19.2 last edited by

                      @barath-19-2 It's apparently wiringPi not wiringpi...

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      B 1 Reply Last reply Reply Quote 1
                      • B
                        barath.19.2 @jsulm last edited by

                        @jsulm tnx it is now saying file format is not recognized
                        Screenshot from 2019-12-06 19-10-58.png

                        jsulm 1 Reply Last reply Reply Quote 0
                        • jsulm
                          jsulm Lifetime Qt Champion @barath.19.2 last edited by

                          @barath-19-2 I asked before: "And it looks like you're not doing cross-compalation?"
                          So, are you doing cross-compilation?
                          The wiringPi library is apparently not compatible with your platform.
                          If you build on your PC/Laptop for Raspberry Pi you have to do cross compilation as Raspberry Pi is ARM and not x86.
                          So, did you set up a cross compilation environment?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply Reply Quote 2
                          • First post
                            Last post