brson / rust-sdl

SDL bindings for Rust
MIT License
179 stars 52 forks source link

Build Failure on OSX #19

Closed xasmx closed 11 years ago

xasmx commented 11 years ago

Trying to build on OSX-10.8.2. libSDL installed using macports.

./configure && make make: *\ No rule to make target /usr/local/lib/libSDLmain.a', needed bylibSDLXmain.a'. Stop.

Edited Makefile SDL_PREFIX to match where macports installed it: SDL_PREFIX ?= /usr/local/lib -> SDL_PREFIX ?= /opt/local/lib

make rustc sdl.rc -o libsdl.dummy error: linking with cc failed with code 1 note: cc arguments: -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -m64 -o libsdl-34b7eedb9132850-0.2.dylib libsdl.o -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -lcore-c3ca5d77d81b46c1-0.6 -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -lstd-4782a756585a81-0.6 -L. -lSDLXmain -framework AppKit -framework Foundation -lSDL -dynamiclib -Wl,-install_name,@rpath/libsdl-34b7eedb9132850-0.2.dylib -lrustrt -Wl,-no_compact_unwind -lmorestack -Wl,-rpath,@executable_path/../../../../../usr/local/lib/rustc/x86_64-apple-darwin/lib -Wl,-rpath,/usr/local/lib/rustc/x86_64-apple-darwin/lib note: ld: library not found for -lSDL clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error make: *\ [libsdl.dummy] Error 101

AngryLawyer commented 11 years ago

I'll see what I can do about getting hold of a Mac to try and reproduce this on.

xasmx commented 11 years ago

I actually got past this by building sdl from source instead of installing it from macports or homebrew, so it's just an inconvenience. Anyway, even after that I'm not able to get the build working. Now I'm getting the following:

cp /usr/local/lib/libSDLmain.a libSDLXmain.a ar -x libSDLXmain.a SDLMain.o || rm -f -f libSDLXmain.a ld -r SDLMain.o -o SDLXMain.o -alias _main _SDLX_main -unexported_symbol main || rm -f -f libSDLXmain.a mv SDLXMain.o SDLMain.o || rm -f -f libSDLXmain.a chmod u+w libSDLXmain.a || rm -f -f libSDLXmain.a ar -r libSDLXmain.a SDLMain.o || rm -f -f libSDLXmain.a rustc sdl.rc -o libsdl.dummy error: linking with cc failed with code 1 note: cc arguments: -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -m64 -o libsdl-34b7eedb9132850-0.2.dylib libsdl.o -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -lcore-c3ca5d77d81b46c1-0.6 -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -lstd-4782a756585a81-0.6 -L. -lSDLXmain -framework AppKit -framework Foundation -lSDL -dynamiclib -Wl,-install_name,@rpath/libsdl-34b7eedb9132850-0.2.dylib -lrustrt -Wl,-no_compact_unwind -lmorestack -Wl,-rpath,@executable_path/../../../../../usr/local/lib/rustc/x86_64-apple-darwin/lib -Wl,-rpath,/usr/local/lib/rustc/x86_64-apple-darwin/lib note: Undefined symbols for architecture x86_64: "_SDL_main", referenced from: -[SDLMain applicationDidFinishLaunching:] in libSDLXmain.a(SDLMain.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error make: *\ [libsdl.dummy] Error 101

labria commented 11 years ago

Same here

grayrest commented 11 years ago

I was getting this error, dug in and figured out what the makefile was doing and kept poking until it compiled. Result was a rust macro error.

If you're on the current homebrew rust (0.5), you need to git co b8b0ce9061ae9e17907b9380a4bc60bf877df2e4 in the rust-sdl directory before doing the make dance. Compiled without issue for me.

DylanSale commented 11 years ago

doing git co b8b0ce9061ae9e17907b9380a4bc60bf877df2e4 in rust-sdl produces the same error

note: Undefined symbols for architecture x86_64: "_SDL_main", referenced from: -[SDLMain applicationDidFinishLaunching:] in libSDLXmain.a(SDLMain.o)

for me (ie, that didn't fix it for me). Rust 0.5, current master branch of rust-sdl, SDL 1.2.15 from homebrew.

I have managed to get it working by adding -alias _SDLX_main _SDL_main to line 37 of the Makefile after the _SDLX_main alias. I'm not sure if that is a sane thing to do however. The output is a libsdl--0.2.0.dylib and a dSYM folder.

The make check command seems to be failing now, though that looks like it is a macro error:

test.rs:97:46: 97:66 error: cannot apply unary operator ! to type ~str test.rs:97 event::QuitEvent => fail!(~"Explicit quit"), ^~~~~~~~ test.rs:103:20: 103:51 error: cannot apply unary operator ! to type ~str test.rs:103 fail!(~"Failed to set video mode"); ^~~~~~~ test.rs:180:40: 181:9 error: cannot apply unary operator ! to type ~str test.rs:180 result::Err(message) => fail!(message) test.rs:181 }; error: aborting due to 3 previous errors

AngryLawyer commented 11 years ago

Rust-SDL is currently built against Incoming, rather than Master, and that might be causing your problems. Try checking out Rust's Incoming branch and building against that.

xasmx commented 11 years ago

For me, I can compile if I check out f2df562e6eaf56a98a5807a2ff5d193e6b4396c6. The next commit from that (4c3d2c7f7a01c97f28ac1564ea39967ed7efc7cc) is that one that breaks the build.

I'm running with incoming and after adding "-alias _SDLX_main _SDL_main" as DylanSale suggested, I'm able to now compile the head revision. Though, not sure if that alias is the right thing to do.

pcwalton commented 11 years ago

@xasmx Is your SDL working after adding the -alias line? Try a simple app that uses set_video_mode, or you could try rust-airhockey or sprocketnes.

The whole reason for these weird shenanigans regarding SDLX_main is that we need SDL's main in order to set up the window properly on the Mac, but Rust also wants to create the main function, so we have to do some renaming in order to make it work. On Linux, SDL's main is not needed, but on Mac it is.

grayrest commented 11 years ago

Following up on this. Looks like my git revision rollback worked because I didn't re-generate the Makefile. I wound up:

I believe I hit all the other errors mentioned in this thread starting with the homebrew rust 0.5 and trying to work around it. I just repeated everything except the rust master build (takes too long) and got the same result so I think that works. Adding an -alias _SDLX_main _SDL_main results in a duplicate symbol error.

@pcwalton Updating the homebrew build to allow for HEAD and devel (docs search devel) targets would simplify things for us interested rust spectators. If the checkpoint builds would work if installed to the proper system locations, that might be a reasonable option for devel. I'd be willing to try to do it but I'll probably need some handholding since I don't know things like whether master or incoming is the correct branch for HEAD.

DylanSale commented 11 years ago

I can confirm compiling with the rust incoming branch works. The alias -alias _SDLX_main _SDL_main line has the duplicate error @grayrest mentions, so don't do that.

AngryLawyer commented 11 years ago

Is anyone still having this issue when building against Incoming with the latest version of Rust-SDL?

xasmx commented 11 years ago

I'll see if I can figure out how to get this tested today, no promises. I upgraded to latest incoming, which broke rust for me completely, so I'll have to get rust itself fixed before I can test this.

xasmx commented 11 years ago

It's now compiling for me out of the box and was also able to compile and run 'demo' from the demo folder. Thanks a lot, everyone! :)

AngryLawyer commented 11 years ago

Excellent! I assume @pcwalton's changes to the way the OSX builder thing in the make file fixed it, the clever chap he is. Anybody else still having this issue?

AngryLawyer commented 11 years ago

I'm going to assume this is fixed and closing it. If anyone else is still having problems, feel free to comment and I'll reopen it.