From 7ef415e1db448edef7001843bc5241e80ca9a9c9 Mon Sep 17 00:00:00 2001 From: Niels Grewe Date: Wed, 27 Jul 2016 01:30:46 +0200 Subject: [PATCH] Ensure linkage of the gnustep-base The linker is smart enough to figure out that we are not using any symbols from the Foundation library, and elides the request to link it. To circumvent this, we define a (unused) function referencing the symbol for NSObject --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 65bbd01..eb63ecd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,9 +18,23 @@ pub use self::object::{INSObject, NSObject}; pub use self::string::{INSCopying, INSMutableCopying, INSString, NSString}; pub use self::value::{INSValue, NSValue}; +#[cfg(any(target_os = "macos", target_os = "ios"))] #[link(name = "Foundation", kind = "framework")] extern { } +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +use objc::runtime::Class; + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[link(name = "gnustep-base", kind = "dylib")] +extern { static _OBJC_CLASS_NSObject : Class; } + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[allow(dead_code)] +unsafe fn get_class_to_force_linkage() -> &'static Class { + &_OBJC_CLASS_NSObject +} + #[macro_use] mod macros;