PistonDevelopers / glfw-rs

GLFW3 bindings and idiomatic wrapper for Rust.
Apache License 2.0
645 stars 123 forks source link

-lglfw Fails #28

Closed leon-vv closed 10 years ago

leon-vv commented 11 years ago

On OSX I got the following error: "ld: library not found for -lglfw". I still got the same error after making sure GLFW was correctly installed.

After a while I figured that glfw uses "libglfw3.a" instead of "libglfw.a". After renaming "/usr/local/lib/libglfw3.a" to "libglfw.a" it worked.

Not sure if anyone else got this error message, but just wanted to point this out.

brendanzab commented 11 years ago

Hm, this is interesting. How did you install GLFW?

On my machine, I have an alias libglfw.dylib that symlinks to libglfw.3.0.dylib.

Did you install GLFW with the BUILD_SHARED_LIBS cmake option?

brendanzab commented 11 years ago

Did you get this to work?

leon-vv commented 11 years ago

Sorry for the late response! At the moment I'm using another computer with Ubuntu, so I can't reproduce the problem. I will get back to you whenever I encounter this issue again.

brendanzab commented 11 years ago

Seeing as I haven't had any other complaints, I'll close this for now, but feel free to reopen it if you still find you have problems. :)

sebcrozet commented 11 years ago

I have seen this problem on three macs (macbook air, macbook pro and macbook pro retina). It happens when you follow the standard installation procedure:

cmake .
make
sudo make install

This creates a libglfw3.a only.

To make it work with -lglfw instead of -lglfw3, one needs, as you said, to set BUILD_SHARED_LIBS to ON, which will create the libraries and simlink.

I guess there should be a notice on glfw-rs' README to tell people they have to change the default cmake config.

brendanzab commented 11 years ago

@sebcrozet So you think this might be a osx-specific problem?

sebcrozet commented 11 years ago

I think this is a problem for anybody installing glfw from the glfw website zipball, because BUILD_SHARED_LIBS is OFF by default. I guess people on linux dont have this problem since their package manager is very likely to install the shared libs too.

jeaye commented 11 years ago

This was a problem for q3 as well, which I mitigated in my configure script.

GLFW static is built: https://github.com/jeaye/q3/blob/master/configure#L34 GLFW shared is built: https://github.com/jeaye/q3/blob/master/configure#L45 GLFW-rs is built after symbolic links are made: https://github.com/jeaye/q3/blob/master/configure#L65

I agree that adding a note in the README would be beneficial.

On Tue, Sep 10, 2013 at 03:25:08AM -0700, Sébastien Crozet wrote:

I think this is a problem for anybody installing glfw from their tarball, because BUILD_SHARED_LIBS is OFF by default. I guess people on linux dont have this problem since their package manager is very likely to install the shared libs too.

— Reply to this email directly or [1]view it on GitHub. [HsRVgEn5y14gQ9FgbvZPHrYflVleBFRD6428LUO1DfUOp1r3CYeVDhMG2UqgJkky.gif]

References

  1. https://github.com/bjz/glfw-rs/issues/28#issuecomment-24149862
neuralvis commented 11 years ago

In osx, installing glfw3 via homebrew with "shared libs" still results in libglfw3 dylibs: https://github.com/Homebrew/homebrew-versions/blob/master/glfw3.rb

My homebrew cellar has the following:

smadhueagle$ ls -1all libglfw* lrwxr-xr-x 1 smadhueagle admin 44 Sep 27 15:31 libglfw3.3.0.dylib -> ../Cellar/glfw3/3.0.2/lib/libglfw3.3.0.dylib lrwxr-xr-x 1 smadhueagle admin 42 Sep 27 15:31 libglfw3.3.dylib -> ../Cellar/glfw3/3.0.2/lib/libglfw3.3.dylib lrwxr-xr-x 1 smadhueagle admin 40 Sep 27 15:31 libglfw3.dylib -> ../Cellar/glfw3/3.0.2/lib/libglfw3.dylib

Can anyone confirm that this is the case for them as well ?

brendanzab commented 11 years ago

The weird thing is that this is how it installs on OSX when you do it directly from the source (not via homebrew):

lib

brendanzab commented 11 years ago

Any idea about homebrew and the cmake build installing glfw under different names @elmindreda?

neuralvis commented 11 years ago

@elmindreda, @bjz - It's possible that this was done in Homebrew to allow multiple versions of glfw to exist side-by-side.

https://github.com/Homebrew/homebrew-versions/blob/master/glfw2.rb https://github.com/Homebrew/homebrew-versions/blob/master/glfw3.rb

My linux glfw install shows libglfw.so, so it's really a "homebrew's" exception to the norm.

brendanzab commented 11 years ago

Does it work on all platforms if you change the link args to use -lglfw3 instead of -lglfw? I can't test it at the moment because of mozilla/rust#9692.

neuralvis commented 11 years ago

No - it fails. -lglfw3 does not work on Linux x86_64, CentOS 6.3.

brendanzab commented 11 years ago

Ack. So I'm guessing that's why I initially used -lglfw. Rust can't link to static libs yet can it?

metajack commented 11 years ago

Servo links glfw statically.

brendanzab commented 10 years ago

Could I have a straw poll of who has a glfw3.* lib and who doesn't?

I am now using homebrew and my /usr/local/lib/ looks like this:

lib

If everyone has a glfw3.*, then I can switch to using -lglfw3 in the linker args.

elmindreda commented 10 years ago

Would it be possible to use pkgconfig? Regardless of the name of the shared library, the pkgconfig file should still be named glfw3.pc.

brendanzab commented 10 years ago

@catamorphism does pkgconfig work with rustpkg at the moment?

brendanzab commented 10 years ago

This is how the glfw docs recommend to link using pkg-config.

brendanzab commented 10 years ago

Ok, made some changes 967e4ebe5ccd220fdf26f9c4d8ab114c8afac07b, hopefully this fixes things.

pinbender commented 10 years ago

On my Mint 15 install, after building glfw3 (from source), I had to change ffi.rs to use -lglfw3 instead of -lglfw.

metajack commented 10 years ago

I think perhaps we should include glfw as a submodule and link it statically like servo does. That would get rid of all the build problems entirely.

rustpkg should be capable of doing this.

brendanzab commented 10 years ago

@metajack: Yeah that might be the best way.

Would somebody be able to help implement that?

metajack commented 10 years ago

I will try to do it. It's on my plate for Servo anyway.

petervaro commented 10 years ago

Any progress?

brendanzab commented 10 years ago

@petervaro: None yet, unless Jack has done anything – always a chance he was waylaid by other work this week. Until then, I'd recommend making a symlink on your PATH as described in the FAQ.

@metajack: any chance you could make this work with rustpkg?

brendanzab commented 10 years ago

@leon-vv The build system has been considerably updated since this issue was created. Is this still an issue for you?

leon-vv commented 10 years ago

I'm not using OSX anymore, so I can't reproduce the original problem, but on Ubuntu everything works fine.

brendanzab commented 10 years ago

Ok, I will close for now. Using pkg-config should have fixed this.

wackywendell commented 9 years ago

I'm not sure if this is my problem or the libraries, but I'm getting a similar error:

wendell ~/code/glfw-rs$ pkg-config --cflags --libs glfw3
-I/usr/include/libdrm -lglfw 
wendell ~/code/glfw-rs$ cargo build --no-default-features --example
   Compiling glfw v0.0.8 (file:///home/wendell/code/glfw-rs)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/wendell/code/glfw-rs/target/debug/examples/window" "/home/wendell/code/glfw-rs/target/debug/examples/window.o" "-Wl,--whole-archive" "-lmorestack" "-Wl,--no-whole-archive" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "/home/wendell/code/glfw-rs/target/debug/libglfw.rlib" "/home/wendell/code/glfw-rs/target/debug/deps/libsemver-97eaa84569c2a87a.rlib" "/home/wendell/code/glfw-rs/target/debug/deps/libbitflags-518ea12e21428edd.rlib" "/home/wendell/code/glfw-rs/target/debug/deps/liblog-54cf393d3c69686f.rlib" "/home/wendell/code/glfw-rs/target/debug/deps/liblibc-2eda841eb12a3090.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib" "-L" "/home/wendell/code/glfw-rs/target/debug" "-L" "/home/wendell/code/glfw-rs/target/debug/deps" "-L" "/home/wendell/.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/wendell/code/glfw-rs/.rust/lib/x86_64-unknown-linux-gnu" "-L" "/home/wendell/code/glfw-rs/lib/x86_64-unknown-linux-gnu" "-Wl,--whole-archive" "-Wl,-Bstatic" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-lglfw3" "-lX11" "-lGL" "-lXxf86vm" "-lXrandr" "-lXi" "-lXcursor" "-lXinerama" "-lc" "-lm" "-ldl" "-lpthread" "-lrt" "-lgcc_s" "-lpthread" "-lc" "-lm" "-Wl,-rpath,$ORIGIN/../../../../../.multirust/toolchains/stable/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lcompiler-rt"
note: /usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status

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

To learn more, run the command again with --verbose.

I used no-default-features because I'm using kiss3d, and it turns them off in its Cargo.toml, and gave me the above error in a package I was trying to make.

Am I doing something wrong, or is this a package error?