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

Program compiled for RPi cannot use 3rd party library #10891

Closed
grav opened this issue Feb 14, 2022 · 2 comments
Closed

Program compiled for RPi cannot use 3rd party library #10891

grav opened this issue Feb 14, 2022 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@grav
Copy link

grav commented Feb 14, 2022

Zig Version

0.9.0

Steps to Reproduce

  1. build portmidi as shared library on Raspberry Pi
  2. copy libportmidi.so to other machine
  3. build example
$ zig build-exe src/midi.zig /path/to/rpi/libportmidi.so -I/path/to/portmidi/pm_common -I/path/to/portmidi/porttime -lc -target arm-linux-musleabihf

  1. copy to RPi and run:
$rpi LD_LIBRARY_PATH=/path/to/portmidi ./midi 

Expected Behavior

Program outputs test-data

Actual Behavior

Program cannot find expected symbols from libasound:

Error relocating /lib/libasound.so.2: __vsnprintf_chk: symbol not found
Error relocating /lib/libasound.so.2: __open_2: symbol not found
Error relocating /lib/libasound.so.2: __xstat: symbol not found
Error relocating /lib/libasound.so.2: __memcpy_chk: symbol not found
Error relocating /lib/libasound.so.2: __strcpy_chk: symbol not found
Error relocating /lib/libasound.so.2: __fxstat: symbol not found
Error relocating /lib/libasound.so.2: __vfprintf_chk: symbol not found
Error relocating /lib/libasound.so.2: dladdr1: symbol not found
Error relocating /lib/libasound.so.2: __sprintf_chk: symbol not found
Error relocating /lib/libasound.so.2: __fprintf_chk: symbol not found
Error relocating /lib/libasound.so.2: __lxstat: symbol not found
Error relocating /lib/libasound.so.2: __snprintf_chk: symbol not found

I've succesfully

  1. run the same test program on my laptop (without the -target option)
  2. run a tiny c program on the RPi that uses the same dynamic libary
  3. linked to a toy c-library I created and run the resulting program on the RPi

I'm aware that it might be my limited understanding of how the toolchain works, but I've already sought assistance in the #zig-help discord channel.

If this issue is off-topic, feel free to close, but any pointers would be greatly appreciated.

@grav grav added the bug Observed behavior contradicts documented or intended behavior label Feb 14, 2022
@zigazeljko
Copy link
Contributor

Since you are dynamically linking to libc, you should use arm-linux-gnueabihf as target.

@grav
Copy link
Author

grav commented Feb 14, 2022

@zigazeljko Thanks, that ended up solving it!

Already tried that path once, but got stuck with a problem with a missing arm-features.h, but I gained a bit more confidence with your answer and tried again :)

A quick google search reveiled an answer in this comment on another issue:
#3287 (comment)

@grav grav closed this as completed Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants