blasrobot
Posts: 5
Joined: Tue Mar 20, 2018 3:53 pm

Error when compiling a .c file using WiringPi library

Tue Apr 17, 2018 9:30 pm

Hello everyone!!

I have installed the Wiring Pi library in my RPi3, using a git from the official site. However, I get the same error whenever I try to compile ANY C FILE (including the examples from the library).

So, for example, if I want to compile the blink.c example (which just blinks an LED):

nicolas@nicolas-X510UAR:~/wiringPi/examples$ gcc blink.c -o blink -lwiringPi

I get:

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

What I am supposed to do? I have already re installed and built the library, and it does not change.

Please help!! Thank you!!!!!!!!

User avatar
joan
Posts: 14886
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Error when compiling a .c file using WiringPi library

Tue Apr 17, 2018 9:38 pm

Perhaps

gcc -pthread blink.c -o blink -lwiringPi

User avatar
PeterO
Posts: 5828
Joined: Sun Jul 22, 2012 4:14 pm

Re: Error when compiling a .c file using WiringPi library

Tue Apr 17, 2018 9:50 pm

You need to learn to use the manual pages...

man crypt...

Code: Select all

CRYPT(3)                   Linux Programmer's Manual                  CRYPT(3)

NAME
       crypt, crypt_r - password and data encryption

SYNOPSIS
       #define _XOPEN_SOURCE       /* See feature_test_macros(7) */
       #include <unistd.h>

       char *crypt(const char *key, const char *salt);

       #define _GNU_SOURCE         /* See feature_test_macros(7) */
       #include <crypt.h>

       char *crypt_r(const char *key, const char *salt,
                     struct crypt_data *data);

       Link with -lcrypt.
Note the last line "Link with -lcrypt"



Code: Select all

RINT(3)                    Linux Programmer's Manual                   RINT(3)

NAME
       nearbyint,  nearbyintf, nearbyintl, rint, rintf, rintl - round to near‐
       est integer

SYNOPSIS
       #include <math.h>

       double nearbyint(double x);
       float nearbyintf(float x);
       long double nearbyintl(long double x);

       double rint(double x);
       float rintf(float x);
       long double rintl(long double x);

       Link with -lm.

Code: Select all

POW(3)                     Linux Programmer's Manual                    POW(3)

NAME
       pow, powf, powl - power functions

SYNOPSIS
       #include <math.h>

       double pow(double x, double y);
       float powf(float x, float y);
       long double powl(long double x, long double y);

       Link with -lm.

Code: Select all

SHM_OPEN(3)                Linux Programmer's Manual               SHM_OPEN(3)

NAME
       shm_open,  shm_unlink  -  create/open  or  unlink  POSIX  shared memory
       objects

SYNOPSIS
       #include <sys/mman.h>
       #include <sys/stat.h>        /* For mode constants */
       #include <fcntl.h>           /* For O_* constants */

       int shm_open(const char *name, int oflag, mode_t mode);

       int shm_unlink(const char *name);

       Link with -lrt.
So now we have "gcc -pthread blink.c -o blink -lcrypt -lm -lrt -lwiringPi"

The order of the libraries might be wrong, but give that a try ans see what you get....

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

blasrobot
Posts: 5
Joined: Tue Mar 20, 2018 3:53 pm

Re: Error when compiling a .c file using WiringPi library

Tue Apr 17, 2018 10:52 pm

Thanks to all of you, sorry for such a stupid question ( I imagine it is).

It worked with:

nicolas@nicolas-X510UAR:~/wiringPi/examples$ gcc blink.c -o blink -pthread -lwiringPi -lm -lrt -lcrypt

Now, I just cant understand why it stopped working from one day to the other, as i did not have to link these functions before.

Thanks

User avatar
joan
Posts: 14886
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Error when compiling a .c file using WiringPi library

Wed Apr 18, 2018 4:42 am

You might have been able to just use -pthread. The libraries which are automatically loaded change from time to time, not randomly, but as the libraries which need them are themselves updated.

blasrobot
Posts: 5
Joined: Tue Mar 20, 2018 3:53 pm

Re: Error when compiling a .c file using WiringPi library

Wed Apr 18, 2018 4:42 pm

It did not seem to work with p thread only. Alright, thank you for the info!

Return to “General discussion”