2

I have written this code to make an LED blink on Raspberry Pi 3 in Ubuntu Mate OS:

#include <wiringPi.h>

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

I tried to compile the code by using:

gcc -o blink blinky.c -lwiringPi

But it fails to compile, and gives me these errors:

/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

I installed all the necessary things for WiringPi, but I am not able find the solution for the above error.

Ethan Smith
  • 67
  • 1
  • 7
  • Try adding `-lpthread` to the end of your `gcc` command. – Mark Setchell Apr 16 '17 at 11:48
  • Yes have used that but it only eliminate the "undefined reference of the pthread" but other remain the same. – Vishnu Prasad P Apr 16 '17 at 13:20
  • 1
    Add `-lcrypt` too then. And please click `edit` under your questions and update it so it accurately reflects where you are and what command you used and what error messages you get. – Mark Setchell Apr 16 '17 at 13:24
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan Dec 01 '17 at 10:44

2 Answers2

2

Try a command more like this:

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

You can replace your own file for temperature.c and temperature output file names.

This invocation was taken from the Makefile in the wiringPi examples directory.

Steven Hepting
  • 12,394
  • 8
  • 40
  • 50
1

defining : add_definitions( -lwiringPi ) and target_link_libraries(${PROJECT_NAME}_class ${wiringPi_LIB} -lcrypt -lrt)

in CMakeLists.txt did the trick for me

Georg
  • 11
  • 3