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

Compiling a binary with glfw-rs rlib fails #77

Closed
HeroesGrave opened this issue Jan 16, 2014 · 12 comments
Closed

Compiling a binary with glfw-rs rlib fails #77

HeroesGrave opened this issue Jan 16, 2014 · 12 comments

Comments

@HeroesGrave
Copy link
Contributor

I am using glfw-rs for 2 projects.

The first is a library, and that compiles fine.

However, when I try to use it in a binary, it gives me this error:

note: lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_callbacks::hce5ef173e2a3e4a8zIaN::v0.1':
glfw.rc:(.text+0x6791): undefined reference to `glfwGetWindowUserPointer'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Drop$Window::drop::h7dde909414fa68faqgaR::v0.1':
glfw.rc:(.text+0x684d): undefined reference to `glfwDestroyWindow'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `init::hb88950b030c32452am::v0.1':
glfw.rc:(.text+0x19d22): undefined reference to `glfwInit'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `terminate::h06a091ee8238c6adaH::v0.1':
glfw.rc:(.text+0x19e12): undefined reference to `glfwTerminate'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_version::he6cde4145c45e0a6a9::v0.1':
glfw.rc:(.text+0x1a2cb): undefined reference to `glfwGetVersion'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_version_string::h1c0968918b96f5fbaQ::v0.1':
glfw.rc:(.text+0x1a332): undefined reference to `glfwGetVersionString'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_primary::h3853b6cbd7313615Y8aj::v0.1':
glfw.rc:(.text+0x1a885): undefined reference to `glfwGetPrimaryMonitor'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_connected::h4be1565a895f30a4Y8av::v0.1':
glfw.rc:(.text+0x1ac97): undefined reference to `glfwGetMonitors'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_pos::he59b4e2435e75c20Y8aC::v0.1':
glfw.rc:(.text+0x1d0b1): undefined reference to `glfwGetMonitorPos'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_physical_size::h62c201859d501fd7Y8aD::v0.1':
glfw.rc:(.text+0x1d141): undefined reference to `glfwGetMonitorPhysicalSize'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_name::h3aaa47ce9a49ff01Y8aE::v0.1':
glfw.rc:(.text+0x1d1b1): undefined reference to `glfwGetMonitorName'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_video_modes::habc1eb616b4f6084Y8aF::v0.1':
glfw.rc:(.text+0x1d222): undefined reference to `glfwGetVideoModes'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_video_mode::h37829ff8c22c4176Y8a5::v0.1':
glfw.rc:(.text+0x1f3f2): undefined reference to `glfwGetVideoMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::set_gamma::hb72e6497bc957badY8af::v0.1':
glfw.rc:(.text+0x1f795): undefined reference to `glfwSetGamma'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::get_gamma_ramp::he5620e904f03cc69Y8ag::v0.1':
glfw.rc:(.text+0x1f7ea): undefined reference to `glfwGetGammaRamp'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Monitor::set_gamma_ramp::h0916bc26c5d52f68Y8aK::v0.1':
glfw.rc:(.text+0x2029e): undefined reference to `glfwSetGammaRamp'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::default::h8b944d383993d970a9::v0.1':
glfw.rc:(.text+0x20632): undefined reference to `glfwDefaultWindowHints'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::red_bits::h7734298ed8e426cdah::v0.1':
glfw.rc:(.text+0x20691): undefined reference to `glfwWindowHint'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::green_bits::h7f16fb821c94c4f7ay::v0.1':
glfw.rc:(.text+0x206f1): undefined reference to `glfwWindowHint'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::blue_bits::h9b7c12b1e849a2f3aP::v0.1':
glfw.rc:(.text+0x20751): undefined reference to `glfwWindowHint'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::alpha_bits::hd09ef5f10535b0f1a6::v0.1':
glfw.rc:(.text+0x207b1): undefined reference to `glfwWindowHint'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `window_hint::depth_bits::h0e050a88d7071becan::v0.1':
glfw.rc:(.text+0x20811): undefined reference to `glfwWindowHint'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o):glfw.rc:(.text+0x20871): more undefined references to `glfwWindowHint' follow
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::create_intern::h792ee9afba3b4e4bzIay::v0.1':
glfw.rc:(.text+0x251e1): undefined reference to `glfwSetWindowUserPointer'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `__extensions__::create_intern::anon::expr_fn::ai':
glfw.rc:(.text+0x3454b): undefined reference to `glfwCreateWindow'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::free_callbacks::h637276bd461f94fdzIag::v0.1':
glfw.rc:(.text+0x35792): undefined reference to `glfwGetWindowUserPointer'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::should_close::h047252be1fe4a503zIak::v0.1':
glfw.rc:(.text+0x358a1): undefined reference to `glfwWindowShouldClose'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_should_close::hadae698fe4194191zIal::v0.1':
glfw.rc:(.text+0x35921): undefined reference to `glfwSetWindowShouldClose'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `__extensions__::set_title::anon::expr_fn::ar':
glfw.rc:(.text+0x35f4b): undefined reference to `glfwSetWindowTitle'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_pos::h69c599f3faf9848dzIas::v0.1':
glfw.rc:(.text+0x35fc1): undefined reference to `glfwGetWindowPos'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_pos::h78e8b5b34c0eb5c2zIat::v0.1':
glfw.rc:(.text+0x36051): undefined reference to `glfwSetWindowPos'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_size::hd7b5c79ab4f4e6e4zIau::v0.1':
glfw.rc:(.text+0x360c1): undefined reference to `glfwGetWindowSize'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_size::h6e6a6ebc34143f20zIav::v0.1':
glfw.rc:(.text+0x36151): undefined reference to `glfwSetWindowSize'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_framebuffer_size::h5ee0e88cea57a5dezIaw::v0.1':
glfw.rc:(.text+0x361c1): undefined reference to `glfwGetFramebufferSize'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::iconify::h9239e05fb0576a94zIax::v0.1':
glfw.rc:(.text+0x36231): undefined reference to `glfwIconifyWindow'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::restore::h84ba1a72d7ea26e4zIay::v0.1':
glfw.rc:(.text+0x36281): undefined reference to `glfwRestoreWindow'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::show::h205b5d6e76e80736zIaz::v0.1':
glfw.rc:(.text+0x362d1): undefined reference to `glfwShowWindow'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::hide::h2056347b2fb7a27ezIaA::v0.1':
glfw.rc:(.text+0x36321): undefined reference to `glfwHideWindow'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_window_mode::h18e6f73c5dabe00bzIaB::v0.1':
glfw.rc:(.text+0x3637f): undefined reference to `glfwGetWindowMonitor'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::is_focused::h29eeb12ea5493e88zIaC::v0.1':
glfw.rc:(.text+0x363f0): undefined reference to `glfwGetWindowAttrib'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::is_iconified::hc298a61aba6ab870zIaD::v0.1':
glfw.rc:(.text+0x36470): undefined reference to `glfwGetWindowAttrib'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_client_api::he1249f6860386d7czIaE::v0.1':
glfw.rc:(.text+0x364f0): undefined reference to `glfwGetWindowAttrib'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_context_version::h2ca46e692fb5857dzIaF::v0.1':
glfw.rc:(.text+0x3655e): undefined reference to `glfwGetWindowAttrib'
glfw.rc:(.text+0x3658d): undefined reference to `glfwGetWindowAttrib'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o):glfw.rc:(.text+0x365bd): more undefined references to `glfwGetWindowAttrib' follow
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_cursor_mode::h16cdc5d48d967c3ezIaN::v0.1':
glfw.rc:(.text+0x36970): undefined reference to `glfwGetInputMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_cursor_mode::h55440baeefd04e0fzIaQ::v0.1':
glfw.rc:(.text+0x36a36): undefined reference to `glfwSetInputMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::has_sticky_keys::h09b9a1262d5b4c15zIaR::v0.1':
glfw.rc:(.text+0x36a90): undefined reference to `glfwGetInputMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_sticky_keys::h0ad44d21847c4abczIaS::v0.1':
glfw.rc:(.text+0x36b20): undefined reference to `glfwSetInputMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::has_sticky_mouse_buttons::h2461e14db5144b47zIaT::v0.1':
glfw.rc:(.text+0x36b80): undefined reference to `glfwGetInputMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_sticky_mouse_buttons::hd8408bc88a9fb7a8zIaU::v0.1':
glfw.rc:(.text+0x36c10): undefined reference to `glfwSetInputMode'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_key::h344e6f53daaaeb6fzIaV::v0.1':
glfw.rc:(.text+0x36c77): undefined reference to `glfwGetKey'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_mouse_button::h86aea726ecf8c2dfzIaW::v0.1':
glfw.rc:(.text+0x36ce7): undefined reference to `glfwGetMouseButton'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_cursor_pos::h947f35b8095d91f3zIaX::v0.1':
glfw.rc:(.text+0x36d7a): undefined reference to `glfwGetCursorPos'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::set_cursor_pos::ha23cc1df091e7831zIaY::v0.1':
glfw.rc:(.text+0x36e09): undefined reference to `glfwSetCursorPos'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `__extensions__::set_clipboard_string::anon::expr_fn::a0':
glfw.rc:(.text+0x36eeb): undefined reference to `glfwSetClipboardString'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_clipboard_string::ha224eb957a8495f0zIa1::v0.1':
glfw.rc:(.text+0x36f41): undefined reference to `glfwGetClipboardString'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `make_context_current::hd639d7cec832c049ab::v0.1':
glfw.rc:(.text+0x37013): undefined reference to `glfwMakeContextCurrent'
glfw.rc:(.text+0x3702f): undefined reference to `glfwMakeContextCurrent'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::is_current_context::hf9cda9699d6bd0a8zIa4::v0.1':
glfw.rc:(.text+0x370da): undefined reference to `glfwGetCurrentContext'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::swap_buffers::he54cab00b29677b0zIa5::v0.1':
glfw.rc:(.text+0x37141): undefined reference to `glfwSwapBuffers'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_x11_window::h3d2e6e10df1aa548zIa6::v0.1':
glfw.rc:(.text+0x37191): undefined reference to `glfwGetX11Window'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Window::get_glx_context::h0185add61ddaf201zIa7::v0.1':
glfw.rc:(.text+0x371e1): undefined reference to `glfwGetGLXContext'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_x11_display::h88612354e98e4880aE::v0.1':
glfw.rc:(.text+0x37222): undefined reference to `glfwGetX11Display'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `poll_events::h860eb0bc14878a18ae::v0.1':
glfw.rc:(.text+0x37262): undefined reference to `glfwPollEvents'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `wait_events::h857bf203a08b782cam::v0.1':
glfw.rc:(.text+0x372a2): undefined reference to `glfwWaitEvents'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::is_present::haf931ace8ec54046rxaJ::v0.1':
glfw.rc:(.text+0x38c08): undefined reference to `glfwJoystickPresent'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::get_axes::h63185762ab9f3267rxaK::v0.1':
glfw.rc:(.text+0x38c8a): undefined reference to `glfwGetJoystickAxes'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::get_buttons::h796fcd1261f65527rxaP::v0.1':
glfw.rc:(.text+0x3a8aa): undefined reference to `glfwGetJoystickButtons'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `Joystick::get_name::hd70983756f55c948rxaA::v0.1':
glfw.rc:(.text+0x3bea8): undefined reference to `glfwGetJoystickName'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_time::h8b5ce6c98c399c9aaS::v0.1':
glfw.rc:(.text+0x3bef2): undefined reference to `glfwGetTime'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `set_time::hcabab35afcda5ac7a3::v0.1':
glfw.rc:(.text+0x3bf52): undefined reference to `glfwSetTime'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `set_swap_interval::h12e4a4b19770bec4aj::v0.1':
glfw.rc:(.text+0x3bfa0): undefined reference to `glfwSwapInterval'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `extension_supported::anon::expr_fn::aF':
glfw.rc:(.text+0x3c5c5): undefined reference to `glfwExtensionSupported'
lib/libglfw-b34bcc5c-0.1.rlib(glfw.o): In function `get_proc_address::anon::expr_fn::aK':
glfw.rc:(.text+0x3cbed): undefined reference to `glfwGetProcAddress'
collect2: error: ld returned 1 exit status

When I recompile glfw-rs as a dynamic library, and try again, it works fine.

I suspect this is a linking problem, and you can't really fix it, but if that is the case, do you at least know of a workaround so I can use glfw-rs as a rlib?

@HeroesGrave
Copy link
Contributor Author

Oh, and I am on Linux 64-bit.

@ghost
Copy link

ghost commented Jan 16, 2014

You might want to pop onto #rust-gamedev on the Mozilla IRC it might be quicker to help you there.

@HeroesGrave
Copy link
Contributor Author

It's not too much of a concern, as I can use shared libraries for now.

@HeroesGrave
Copy link
Contributor Author

Maybe this is part of the same issue as #75?

@brendanzab
Copy link
Member

Hm, does using pkg-config to link to the libraries directly while calling rustc work? I need to get around to documenting this sorry.

@zhanrnl
Copy link

zhanrnl commented Jan 19, 2014

I'm experiencing this very issue (on Ubuntu 13.10). @HeroesGrave and others: how does your temporary workaround work? I've been trying to compile glfw-rs the recommended way with CMake and mkdir build; cd build; cmake ..; make lib which gives me a .rlib file, but I see the error when trying to compile an application linking to that .rlib file. Should I manually rustc something?

@HeroesGrave
Copy link
Contributor Author

Go into src/glfw/lib.rs, and add #[crate_type="dylib"]; under #[crate_type="rlib"];.

Then run make lib again and it will output in both rlib and so files. Then you can put the so in your project and it should work.

@zhanrnl
Copy link

zhanrnl commented Jan 20, 2014

Thanks! I added that line, but glfw-rs still didn't build, with the linker complaining that my static GLFW library couldn't be used and suggesting to "recompile with -fPIC". The solution required adding the C compiler flag -fPIC to the original compilation of the GLFW static library, which I did by adding a add_definitions(-fPIC) directive to the GLFW CMakeLists.txt.

I'm not exactly sure why this caused everything to work, since my knowledge of C compiling/linking is very poor. But this solved the problem for me; hopefully this is useful information for @bjz or other contributors of this library in making the build procedure easier for future users.

@brendanzab
Copy link
Member

Hmm interesting. Might have to ask @metajack so enlighten us.

It would be cool to have a CMake option to build either a static or dynamic library (as glfw itself does).

@HeroesGrave
Copy link
Contributor Author

I tried again to make sure there was no derp on my behalf, and the result was exactly the same.

Maybe you should make it compile to both static and dynamic. That would somewhat solve this without breaking it on windows.

@brendanzab
Copy link
Member

I'm currently working on regigging the build script - CMake is a big pain, but it seems like the best we have, unfortunately. Sorry for the wait on this.

@HeroesGrave
Copy link
Contributor Author

Well it seems that this is more-or-less fixed.

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

3 participants