简体   繁体   English

链接接线Pi Shared Object 库,用于 Ubuntu 20.04 中的 RPI4

[英]Linking wiringPi Shared Object Library for RPI4 in Ubuntu 20.04

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:我只是想编译一个包含wiringPi.h的cpp文件:

#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.所有导致相同的 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'.第一个 g++ 示例是在安装了 WiringPi 之后运行的,如网站 'sudo apt install WiringPi' 中所述。 After that didn't work, I noticed Ubuntu came with a pre-installed version (ver2):在那之后没有用,我注意到 Ubuntu 带有预装版本(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/". 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.我只是假设它以相同的方式包含“wiringPi.h”,但我也尝试了一些猜测“libwiringPi.h”、“wiringPi2.h”等。

When I look inside the.so.2 file, I see some functions that I would like to get my hands on:当我查看.so.2 文件时,我看到了一些我想使用的功能:

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 .我也会使用wiringPi的网站版本,但在运行sudo apt install wiringPi后找不到任何库文件。 I'll be happy to get either version working for me.我很乐意让任何一个版本都为我工作。 Thanks in advance!提前致谢!

After digging in deeper to why no headers are installed.在深入研究为什么没有安装标头之后。 I guess headers aren't included unless it's a '-dev' package.我猜标题不包括在内,除非它是'-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.所以我找到了这个 package 代替: https://packages.ubuntu.com/hirsute/libwiringpi-dev的头文件让我没有编译错误。 I still have to try out some functions but that would be separate issue I think.我仍然需要尝试一些功能,但我认为这将是一个单独的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM