Skip to content

Commit aca6ed5

Browse files
committed
Fix linking to libobjc2 v2.0
1 parent d1bb3e6 commit aca6ed5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

objc2/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,17 @@ pub mod __gnustep_hack {
178178
#[link(name = "gnustep-base", kind = "dylib")]
179179
// This linking doesn't have to be on the correct `extern` block.
180180
extern "C" {
181-
static _OBJC_CLASS_NSObject: Class;
181+
// The linking changed in libobjc2 v2.0
182+
#[cfg_attr(feature = "gnustep-2-0", link_name = "._OBJC_CLASS_NSObject")]
183+
#[cfg_attr(not(feature = "gnustep-2-0"), link_name = "_OBJC_CLASS_NSObject")]
184+
static OBJC_CLASS_NSObject: Class;
185+
// Others:
186+
// __objc_class_name_NSObject
187+
// _OBJC_CLASS_REF_NSObject
182188
}
183189

184190
pub unsafe fn get_class_to_force_linkage() -> &'static Class {
185-
unsafe { core::ptr::read_volatile(&&_OBJC_CLASS_NSObject) }
191+
unsafe { core::ptr::read_volatile(&&OBJC_CLASS_NSObject) }
186192
}
187193

188194
#[test]

0 commit comments

Comments
 (0)