Skip to content

bundle feature is broken on macOS #1034

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

Open
saty9 opened this issue Oct 3, 2020 · 6 comments
Open

bundle feature is broken on macOS #1034

saty9 opened this issue Oct 3, 2020 · 6 comments

Comments

@saty9
Copy link

saty9 commented Oct 3, 2020

Possibly relates to #1029

The bundled feature gives an error if you attempt to run the produced executable directly instead of using cargo run.

tested with version 0.34.{0,2,3}

./CrossFade
dyld: Library not loaded: @rpath/libSDL2-2.0.dylib
  Referenced from: /Users/kyle/CLionProjects/bedlam-cues-early-experiments/rust/target/release/./CrossFade
  Reason: image not found
zsh: abort      ./CrossFade
@Cobrand
Copy link
Member

Cobrand commented Oct 4, 2020

That is because cargo run adds this: https://github.com/Rust-SDL2/rust-sdl2/blob/master/sdl2-sys/build.rs#L525

Which tells your binary where to find SDL2 if it's needed. When you start your binary without cargo run, your OS can't find the dynamic library and outputs this message.

Two solutions:

  • Copy the dylib to the same folder your binary is. Is in target/release/sdl2-sys-xxx/... and should be named SDL2-2.0.dylib or something.
  • Use the static-link feature which compiles sdl2 statically instead of dynamically, removing the need of having sdl2.dylib

@saty9
Copy link
Author

saty9 commented Oct 6, 2020

Thanks for speedy response that makes sense. Would you consider a pr that added a feature flag to copy that dylib/.something(I cant remember the linux equivalent) into the final target dir? I see this is already done for windows.

@Cobrand
Copy link
Member

Cobrand commented Oct 6, 2020

We already have many features so I'm not too fond of it. Windows does this because it's necessary for the tests/cargo run to run well, but it's not necessary for OSX and linux.

One thing you could do, is adding documentation about it instead. I have no idea where the best place to document that would be, though, perhaps the readme?

@TheRadioGuy
Copy link
Contributor

One thing you could do, is adding documentation about it instead. I have no idea where the best place to document that would be, though, perhaps the readme?

I think we can use Wiki and add Troubleshooting section there

@schell
Copy link

schell commented Jan 18, 2021

I just tried compiling sdl2 statically using the static-link feature and ran into this error:

cargo build
   Compiling sdl2 v0.34.3
   Compiling sdl2-sys v0.34.3
error: failed to add native library /Users/schell/code/new-gods/target/debug/build/sdl2-sys-25280f9504461f51/out/lib/libSDL2main.a: file too small to be an archive

error: aborting due to previous error

error: could not compile `sdl2-sys`

ebkalderon added a commit to ebkalderon/dss-coding-assignment that referenced this issue Jan 22, 2021
It turns out that the "static-link" feature flag for the `sdl2-sys`
crate doesn't link `SDL2_Image` nor `SDL2_TTF`) into it, and the
"bundled" feature flag only fetches the main `libsdl2` library at build
time and not `SDL2_Image`. Plus, it seems that "bundled" and
"static-link" are also broken in other ways, at the time of writing:

Rust-SDL2/rust-sdl2#778
Rust-SDL2/rust-sdl2#851
Rust-SDL2/rust-sdl2#858
Rust-SDL2/rust-sdl2#1017
Rust-SDL2/rust-sdl2#1029
Rust-SDL2/rust-sdl2#1034

For the sake of reliability, this commit disables both Cargo feature
flags described for the `sdl2` dependency (thereby requiring the user to
install external dependencies) and introduces a detailed setup guide in
the `README.md` for Windows, macOS, and Linux.
@ctrlcctrlv
Copy link

Yes, static-link also broken, but I can't just disable it, I need it on some platforms, and I shouldn't have to disable it.

Cf. MFEK/glif#220, MFEK/glif#127.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants