Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to 'ws2811_...' #478

Open
R3tr0BoiDX opened this issue Dec 2, 2021 · 2 comments
Open

undefined reference to 'ws2811_...' #478

R3tr0BoiDX opened this issue Dec 2, 2021 · 2 comments
Labels
notice Issues that are solved/do not require input, but preserved and marked of interest to users.

Comments

@R3tr0BoiDX
Copy link

R3tr0BoiDX commented Dec 2, 2021

I did installed the library as described in the README by doing

cd build
cmake -D BUILD_SHARED=ON -D BUILD_TEST=OFF ..
cmake --build .
sudo make install


==> It says:

[100%] Built target ws2811
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libws2811.so
-- Installing: /usr/local/include/ws2811/ws2811.h
-- Installing: /usr/local/include/ws2811/rpihw.h
-- Installing: /usr/local/include/ws2811/pwm.h
-- Installing: /usr/local/include/ws2811/clk.h
-- Installing: /usr/local/include/ws2811/dma.h
-- Installing: /usr/local/include/ws2811/gpio.h
-- Installing: /usr/local/include/ws2811/mailbox.h
-- Installing: /usr/local/include/ws2811/pcm.h
-- Installing: /usr/local/lib/pkgconfig/libws2811.pc

However, if I want to compile my code with gcc main.c -o test, I get main.c:(.text+0x18): undefined reference to 'ws2811_fini' for example.

My main.c:
#include <ws2811/ws2811.h> int main(int argc, char const *argv[]) { return 0; }

@Gadgetoid
Copy link
Collaborator

The header file "declares" all the functions you're using, but the object file or library is responsible for "defining" them.

You need to add -lws2811 to instruct gcc to link against the ws2812 library and include the definitions of ws2811_fini. In the simplest sense this either smooshes your code and the library code together into a single executable (static linking) or allows gcc to create a binary that knows where to find the library file dynamic linking).

So:

gcc main.c -lws2811 -o test

@KC5-BP
Copy link

KC5-BP commented Dec 8, 2021

Hello LED pals ;)

In advance, if you encounter that issue after linking the -lws2811 ('cause I did) :
$ gcc main.c -lws2811 -o test
/usr/bin/ld: /usr/local/lib/libws2811.a(ws2811.c.o): in function ws2811_set_custom_gamma_factor:
ws2811.c:(.text+0x2934): undefined reference to pow
collect2: error: ld returned 1 exit status

Just link the math lib. into the cmd as follow :
$ gcc main.c -lws2811 -lm -o test

@Gadgetoid Gadgetoid added the notice Issues that are solved/do not require input, but preserved and marked of interest to users. label Jan 24, 2022
@Gadgetoid Gadgetoid reopened this May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notice Issues that are solved/do not require input, but preserved and marked of interest to users.
Projects
None yet
Development

No branches or pull requests

3 participants