Ubuntu Mate上的WiringPi

时间:2017-04-16 10:57:20

标签: c++ c gcc raspberry-pi

我已编写此代码,以便在Ubuntu Mate OS中的Raspberry Pi 3上闪烁LED:

#include <wiringPi.h>

int main(void){
    wiringPiSetup();
    pinMode(0, OUTPUT);
    while(1){
        digitalWrite(0, HIGH);
        delay(500);
        digitalWrite(0, LOW);
        delay(500);
    }
    return 0;
}

我尝试使用以下代码编译代码:

gcc -o blink blinky.c -lwiringPi

但它无法编译,并给了我这些错误:

/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `crypt'
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `rint'
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `pthread_join'
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `pthread_create'
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `pow'
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `shm_open'
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../../lib/libwiringPi.so: undefined reference to `pthread_cancel'
collect2: error: ld returned 1 exit status

我为WiringPi安装了所有必要的东西,但是我找不到上述错误的解决方案。

2 个答案:

答案 0 :(得分:1)

尝试更像这样的命令:

gcc -O3 -Wall -I/usr/local/include -Winline -pipe -L/usr/local/lib temperature.c  -lwiringPi -lwiringPiDev -lpthread -lm -lcrypt -lrt -o temperature

您可以将自己的文件替换为temperature.ctemperature输出文件名。

此调用取自wiringPi Makefile目录中的examples

答案 1 :(得分:0)

定义: add_definitions( -lwiringPi )target_link_libraries(${PROJECT_NAME}_class ${wiringPi_LIB} -lcrypt -lrt)

在CMakeLists.txt中,我成功了