c++ program cannot link to bcm_host.so on Raspian bullseye

29 Views Asked by At

I'm working on a c++ program that interacts with the CEC bus on a Raspberry Pi Zero W, running Raspian Bullseye lite. I'm getting all kinds of errors trying to link the program. The files compile fine, and can find the headers, and it looks like the linker can find the .so objects (since it doesn't complain about that). However, it can't find any references to the symbols:

usr/bin/ld: build/main.o: in function `initCEC()':
main.cpp:(.text+0xa0c): undefined reference to `bcm_host_init'
/usr/bin/ld: main.cpp:(.text+0xa10): undefined reference to `vcos_init'
/usr/bin/ld: main.cpp:(.text+0xa1c): undefined reference to `vchi_initialise'
/usr/bin/ld: main.cpp:(.text+0xa5c): undefined reference to `vchi_connect'
/usr/bin/ld: main.cpp:(.text+0xa9c): undefined reference to `vc_vchi_cec_init'
/usr/bin/ld: main.cpp:(.text+0xaa4): undefined reference to `vc_cec_set_passive'
/usr/bin/ld: main.cpp:(.text+0xadc): undefined reference to `vc_cec_register_callback'
/usr/bin/ld: main.cpp:(.text+0xae8): undefined reference to `vc_tv_register_callback'
/usr/bin/ld: main.cpp:(.text+0xaec): undefined reference to `vc_cec_register_all'
/usr/bin/ld: main.cpp:(.text+0xb20): undefined reference to `vc_cec_register_command'

This all worked fine on an older version of Raspian (buster). I've noticed that the header and lib files for cec moved from /opt/vc/* to /usr/*. In addition, I only see libbcm_host.so.0 and ilk, and not libbcm_host.so.

Not sure what's going on. Any ideas?

Update

Here are the compiler and linker commands:

g++ -Wall -c -I. -I/usr/include main.cpp -o build/main.o
g++ -Wall -L/usr/lib -lbcm_host -lvchiq_arm -lvcos -lpthread build/main.o -o build/main
0

There are 0 best solutions below