2

I work with ODROID-C2. I have installed the wiringPi library followed the instructions (from page https://wiki.odroid.com/odroid-c2/application_note/gpio/wiringpi):

$ sudo apt install git

$ git clone https://github.com/hardkernel/wiringPi

$ cd wiringPi

$ sudo ./build

and finaly I get the information "All Done". However during the instalation among different common warnings (e.g. "ignoring return value of ...") I get the following warning (e.g.): "implicit declatration of function 'pinMode' [-Wimplicit-function-declaration]". Similar warnings related to the diffrent functions appear many times during library instalation. After instalation the usage of the command gpio readall allows to get the whole map of pins. Moreover, if I add the library to my program in C(#include <wiringPi.h>), the program is compiled successfully. However, when I use the command from library (e.g. wiringPiSetup();), the compilation fails and the following error appears: 16: error: 'wiringPiSetup' was not declared in this scope. My simple code bellow:

#include <unistd.h>
#include <wiringPi.h> 
#include <cstdio>
using namespace std;

int main (void)
{
    wiringPiSetup();
    while (1)
    {
        printf("*** T E S T ***\n");
        usleep(100000);   
    }

}

How can I fix the problem with wiringPi library?

Bob SO
  • 65
  • 6
  • Did you provide your compiler collection an argument to link `wiringPi`? There is a snippet on the page you linked that does exactly that. It's the first snipper in Odroid-C2 section (look at `-lwiringPi` argument). Also take a look [at gcc's `-l` option](https://www.rapidtables.com/code/linux/gcc/gcc-l.html) – pbn Jan 02 '19 at 10:44
  • I use the following command to compile the file in Geany: `gcc -Wall -c "%f" -lwiringPi` – Bob SO Jan 02 '19 at 10:53
  • What happens when you add `extern void wiringPiSetup (void);` before `int main`? – pbn Jan 02 '19 at 11:10
  • After adding above line a new error appears: `undefined reference to wiringPiSetup` – Bob SO Jan 02 '19 at 11:16
  • Well it means that `wiringPi` library is not available under default path. – pbn Jan 02 '19 at 11:21
  • You can check the paths by using [this answer](https://stackoverflow.com/a/29546339/2429333) – pbn Jan 02 '19 at 11:23
  • IIRC when you are not providing any `-L` option to the compiler you will get only the libraries that are listed by running `ldconfig --verbose`. – pbn Jan 02 '19 at 11:28
  • After running `ldconfig --verbose` I get: `/usr/local/lib:` `libwiringPi.so -> libwiringPi.so.2.44` and `libwiringPiDev.so -> libwiringPiDev.so.2.44`. – Bob SO Jan 02 '19 at 11:42
  • Could you check if `wiringPiSetup` symbol is in `libwiringPi.so` by running `nm -g /usr/local/lib/libwiringPi.so`? – pbn Jan 02 '19 at 11:51
  • After running above commend I've just got list of some "functions" (or someting like that) with I suppose adresses written in hex on the left. I'm not familiar with linux-systems, so is this correct? There is `wiringPiSetup` on this list. – Bob SO Jan 02 '19 at 13:23
  • This is a list of symbols defined in the library. It's a wild guess but try changing options order in build command to `gcc -Wall -lwiringPi -c "%f"`. – pbn Jan 02 '19 at 13:39
  • I've tried but still is wrong. – Bob SO Jan 02 '19 at 13:55
  • Is there an alternative in geany to provide libraries to link to the final target? I just realised that '-c' means it is an intermediary object compilation. You need to add this library wiringPi to final linking. – pbn Jan 02 '19 at 13:57
  • I'm not sure that I understand correctly. After compilation, I can click button Build which runs the following command:'gcc - Wall -o "%e" "%f" -lwiringPi' , but this other action while the error occures during the compilation. – Bob SO Jan 02 '19 at 14:23
  • 1
    By the way, you are using `` . It's C++ library. Can this be related? Are you sure you are compiling with gcc and not `g++`? Maybe you should edit your `g++` compilation flags? – pbn Jan 02 '19 at 14:32
  • 1
    Regarding your understanding correctly, please read [this](https://stackoverflow.com/a/6264256/2429333) to get deeper understanding how the process works. – pbn Jan 02 '19 at 14:41

0 Answers0