2016-07-01 41 views
1

我想動態鏈接一個Rust .so庫與Linux中的C程序與gcc。在沒有錯誤只使用dlopendlclose結果,但我得到了下面的代碼段故障:如何在C中動態加載Rust庫?

char * (*my_function)(char *); 
char *my_input_string = "foo"; 

//...abbreviated code... 

my_function = dlsym(handle, "my_function"); 
char *my_output_string = (*my_function)(my_input_string); 

我使用gcc -g foo.c -ldl -o foo編譯,如果該事項。

我知道它找到符號,因爲我在鏽庫中使用#[no_mangle]my_function指針不爲空

+0

'my_function'的Rust簽名是什麼? – malbarbo

+0

@malbarbo它是'pub extern「C」fn my_function(my_string:* const c_char) - > * const c_char' –

回答

0

我跑它通過gdb和原來的庫試圖調用一個函數中調用該計劃不存在。