Skip to content

Commit ef683b9

Browse files
committed
Print error on dlopen error
1 parent a14a935 commit ef683b9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

gccjit_sys/src/dynload.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ pub use self::platform::Library;
44

55
#[cfg(unix)]
66
mod platform {
7-
use std::ffi::{CStr, c_int, c_void};
7+
use std::ffi::{CStr, c_char, c_int, c_void};
88

99
#[link(name="dl")]
1010
extern "C" {
1111
fn dlopen(filename: *const i8, flag: c_int) -> *mut c_void;
1212
fn dlsym(handle: *mut c_void, symbol: *const i8) -> *mut c_void;
1313
fn dlclose(handle: *mut c_void) -> c_int;
14+
fn dlerror() -> *const c_char;
1415
}
1516

1617
pub struct Library(*mut c_void);
@@ -23,9 +24,13 @@ mod platform {
2324
const RTLD_NOW: c_int = 2;
2425
let handle = dlopen(path.as_ptr(), RTLD_NOW);
2526
if handle.is_null() {
27+
let cstr = dlerror();
28+
let cstr = CStr::from_ptr(cstr);
29+
eprintln!("Dlerror: {:?}", cstr);
2630
None
2731
}
2832
else {
33+
eprintln!("Loading worked HERE");
2934
Some(Self(handle))
3035
}
3136
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ fn with_lib<T, F: Fn(&Libgccjit) -> T>(callback: F) -> T {
125125
pub fn load(path: &CStr) -> bool {
126126
let lib =
127127
LIB.get_or_init(|| {
128-
unsafe { Libgccjit::open(path) }
128+
let lib = unsafe { Libgccjit::open(path) };
129+
eprintln!("Is some: {}", lib.is_some());
130+
lib
129131
});
130132
lib.is_some()
131133
}

0 commit comments

Comments
 (0)