JoachimSchurig / CppGPIO

C++14 GPIO library for embedded systems on Linux
99 stars 27 forks source link

Undefined reference when compiling example code #11

Closed marcs7 closed 2 years ago

marcs7 commented 2 years ago

When compiling the example code

#include <chrono>
#include <cppgpio.hpp>
int main()
{
    // use gpio #18

    GPIO::DigitalOut out(18);

     //switch output to logical 1 (3.3V)

    out.on();

    // wait some time

    std::this_thread::sleep_for(std::chrono::milliseconds(1));

    // switch it off again

    out.off();

    return 0;
}

the following error appear

Error       undefined reference to `GPIO::DigitalOut::DigitalOut(unsigned int)' 

How can I solve it?

JoachimSchurig commented 2 years ago

you either need to sudo make install the library first before compiling the sample, or tell the linker where to find it with -L, and in both cases use -lcppgpio to tell the linker to use the library

marcs7 commented 2 years ago

I've installed the library and added the -lcppgpio and a new error comes up Error /usr/lib/gcc/aarch64-linux-gnu/9/../../../../lib/libcppgpio.so: undefined reference to `pthread_create'
Solved added pthread to linker option in viusal studio

Close issue