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

Problems with linking to SDL2 framework on OSX #539

Open
lundstroem opened this issue Sep 29, 2016 · 10 comments
Open

Problems with linking to SDL2 framework on OSX #539

lundstroem opened this issue Sep 29, 2016 · 10 comments
Labels

Comments

@lundstroem
Copy link

I'm trying to get it to work but every combination of "use_mac_framework" as described in the info results in error. I'm using SDL 2.0.4 and it's located at /Library/Frameworks/SDL2.framework
rustc version is 1.11.0 (9b21dcd6a 2016-08-15)

Cargo.toml:

[package]

name = "hello_sdl2"
version = "0.0.1"
authors = [ "Harry Lundström <palestonesoftware@gmail.com>" ]

[dependencies.sdl2]
features = ["use_mac_framework"]
version = "0.23.0"

cargo clean
cargo build

error: linking with `cc` failed: exit code: 1
note: "cc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/hello_sdl2.0.o" "-o" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/hello_sdl2" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug" "-L" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libsdl2-7a2e4d6edae36277.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum-45a7f1df1ffbcf4c.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum_rational-7726582d22be0b52.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum_iter-50df698bc905252c.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/liblazy_static-359f5533c970cd71.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libsdl2_sys-129b74684993c958.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libbitflags-b8c7fb7df9b2bc2e.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum_complex-704ef091ce88b7b2.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum_bigint-a144dbec313e5e23.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum_integer-52fdddf28cd8e924.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/libnum_traits-a6dde7de4ab4b779.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/librustc_serialize-3561541d79c18212.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/librand-49a08859d086fffe.rlib" "/Users/d/Documents/rust-workspace/hello_sdl2/target/debug/deps/liblibc-1417726cb94dbc83.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libunwind-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-39b92f95.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-39b92f95.rlib" "-framework" "SDL2" "-framework" "SDL2" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: ld: framework not found SDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
error: Could not compile `hello_sdl2`.

cargo test --features use_mac_framework
error: Package hello_sdl2 v0.0.1 (file:///Users/d/Documents/rust-workspace/hello_sdl2) does not have these features: use_mac_framework

Maybe I'm missing something obvious, but any pointers would be helpful.
/ Harry

@jonathan-quarles
Copy link

I see that you closed this issue yet I have the same problem as described here. I hope if you find the solution that you'll share it with me.

@lundstroem lundstroem reopened this Aug 20, 2017
@lundstroem
Copy link
Author

Hello Jonathan! Unfortunately I never got any response to this issue, and I never found a solution, so I got tired of it and closed it. But now I've re-opened it again. I wish you better luck!

@Cobrand
Copy link
Member

Cobrand commented Aug 20, 2017

try features = ["sdl2-sys/use-mac-framework"]?

@jonathan-quarles
Copy link

jonathan-quarles commented Aug 21, 2017

@lundstroem, Thanks for reopening the issue. @Cobrand, I tried your suggestion but i got this error: error: feature names may not contain slashes: 'sdl2-sys/use-mac-framework'. I wonder if there's a different way to put that.

@Cobrand
Copy link
Member

Cobrand commented Aug 21, 2017

maybe cargo run --features "sdl2/sdl2-sys/use-mac-framework"? I'm pretty sure you can enable a feature of dependency of a dependency, which is probably what you want there (the "use_mac_framework" feature is in sdl2-sys, the one in sdl2 is merely a shortcut).

@jonathan-quarles
Copy link

@Cobrand, I just got the same error I did before (error: feature names may not contain slashes: sdl2-sys/use-mac-framework`) after running that. It seems from this issue here, that slashes are a bug on mac (or something).

@Darkspear7
Copy link
Contributor

@jonathan-quarles I also encounted this problem when trying to run a toy project. I was able to make it work with this package configuration:

[package]
name = "platform"
version = "0.1.0"
authors = ["Darkspear7 <blaj.dragos@gmail.com>"]

[dependencies]
platform_traits = { path = "../platform_traits", version = "0.1.0" }
sdl2 = "0.31"

[dependencies.sdl2-sys]
features = ["use_mac_framework"]

@siabard
Copy link

siabard commented Mar 12, 2018

It seems very similar with White-Oak/qml-rust#42.

I have a success with my sample project as below.

  1. Install SDL2, SDL2_mixer, SDL2_image, SDL2_ttf with package (.dmg)
  2. install SDL2_gfx from source. (you may need brew install automake)
  3. add build.rs on project root.
fn main() {
    println!("cargo:rustc-link-search=framework=/Library/Frameworks")
}
  1. add build to Cargo.toml
[package]
...
build="build.rs"

[dependencies.sdl2]
version = "*"
default-features = false
features = ["use_mac_framework","image","ttf","mixer","gfx"]

@gamecubate
Copy link

gamecubate commented Apr 10, 2019

I think you can close this. I had the same problem 2 days ago but this issue's previous posts led me to the answer, namely (at least in my case):

  1. Download and copy the sdl2_ttf framework for macOS to /Library/Frameworks
  2. In Cargo.toml, replace
[dependencies]
...
sdl2 = "0.32.2"

with

[dependencies.sdl2]
version = "0.32.2"
default-features = false
features = ["ttf"]

  1. cargo clean ; cargo run

dadleyy added a commit to atsheehan/zero-to-gamedev that referenced this issue Dec 7, 2019
dadleyy added a commit to atsheehan/zero-to-gamedev that referenced this issue Jan 14, 2020
@cedeber
Copy link

cedeber commented Oct 19, 2022

I feel like the build.rs of "rust-sdl2" needs to be:

fn main() {
    #[cfg(any(target_os = "openbsd", target_os = "freebsd"))]
    println!(r"cargo:rustc-link-search=/usr/local/lib");

    #[cfg(all(target_os = "macos", feature = "use_mac_framework"))]
    println!("cargo:rustc-link-search=framework=/Library/Frameworks")
}

Isn't it?

At least without that I can't run cargo test --features use_mac_framework on macOS.

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

No branches or pull requests

7 participants