0

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
Heston Liebowitz
  • 1,625
  • 17
  • 12
  • Can we see the compiler and linker full commandline ? – Jeffrey Apr 14 '22 at 00:39
  • I updated the original question with the g++ commands I'm using. It's also worth mentioning that this is a fresh install of Bullseye. – Heston Liebowitz Apr 14 '22 at 14:42
  • Did you try the opposite order ? https://stackoverflow.com/questions/7826448/linking-libraries-with-gcc-order-of-arguments – Jeffrey Apr 14 '22 at 14:46
  • Yep, that was it. Thanks @Jeffrey! – Heston Liebowitz Apr 14 '22 at 17:21
  • Awesome. Glad it's solved. Voting to close duplicate: [Linking libraries with gcc: order of arguments](https://stackoverflow.com/questions/7826448/linking-libraries-with-gcc-order-of-arguments) – Jeffrey Apr 14 '22 at 18:16
  • And for what it's worth, I can't understand what went on in GCC's devs mind when they implemented this change. It trades off a very frequent build issue and confusion source for a few milliseconds of scanning libraries both ways. – Jeffrey Apr 14 '22 at 18:19

0 Answers0