Linking wiringPi Shared Object Library for RPI4 in Ubuntu 20.04

571 Views Asked by At

I'm hoping someone can help me look into something that I think should be somewhat trivial.

I'm simply trying to compile a cpp file that includes wiringPi.h:

#include <wiringPi.h>

int main(){ return 0; }

I've run tens of different commands with different linking parameters and no matter what it always says:

testing_spi.cpp:2:10: fatal error: wiringPi.h: No such file or directory
    2 | #include "wiringPi.h"
      |          ^~~~~~~~~~~~
compilation terminated.

For example,

g++ -lwiringPi -o test test.cpp
g++ -L/usr/lib/aarch64-linux-gnu -lwiringPi -o test_spi testing_spi.cpp
...

All resulting in the same output. I've been at this for a few hours and am confused why it's not linking.

The first g++ example was ran after installing wiringPi as stated on the website 'sudo apt install wiringPi'. After that didn't work, I noticed Ubuntu came with a pre-installed version (ver2):

sudo apt list --installed | grep wiring

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libwiringpi2/focal,now 2.50-0ubuntu1 arm64 [installed]
wiringpi/focal,now 2.50-0ubuntu1 arm64 [installed]

But the only documentation I could find from Ubuntu is trash: https://packages.ubuntu.com/focal/amd64/libwiringpi2/filelist I was able to find those shared object files inside the directory "/usr/lib/aarch64-linux-gnu/". I'm just assuming it get included the same way "wiringPi.h" but I've also tried some guesses "libwiringPi.h", "wiringPi2.h", etc.

When I look inside the .so.2 file, I see some functions that I would like to get my hands on:

nm -gD --demangle /usr/lib/aarch64-linux-gnu/libwiringPi.so.2
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 U __ctype_b_loc
                 w __cxa_finalize
                 U __errno_location
                 U __fprintf_chk
                 w __gmon_start__
                 U __printf_chk
                 U __snprintf_chk
                 U __sprintf_chk
                 U __stack_chk_fail
                 U __stack_chk_guard
                 U __vsnprintf_chk
000000000000b910 T _drcSetupNet
0000000000023fd0 B _wiringPiClk
0000000000023fb8 B _wiringPiGpio
0000000000023fb0 B _wiringPiPads
0000000000023fc0 B _wiringPiPwm
0000000000023fd8 B _wiringPiTimer
0000000000023fc8 B _wiringPiTimerIrqRaw
                 U access
000000000000a180 T ads1115Setup
0000000000005b98 T analogRead
0000000000005bd8 T analogWrite

But I've having too much trouble trying to get it to link properly. Any help would be appreciated on this. I've been staring at this way too long.

I would also use the website version of wiringPi but couldn't locate any of the library files after running sudo apt install wiringPi. I'll be happy to get either version working for me. Thanks in advance!

1

There are 1 best solutions below

0
On

After digging in deeper to why no headers are installed. I guess headers aren't included unless it's a '-dev' package. So I found this package instead: https://packages.ubuntu.com/hirsute/libwiringpi-dev which has the headers that let me compile without error. I still have to try out some functions but that would be separate issue I think.