I am seriously impressed with how easy the attribute linkmakes reference to shared libraries. However, I am interested in knowing the details of the attribute and its comparison with the binding in C. For example, given the following Rust code
#[allow(bad_style)]
struct wl_display;
fn main() {
#[link(name="wayland-client", kind="dylib")]
extern {
fn wl_display_connect(name: *const u8) -> *mut wl_display;
}
}
Will it move closer to something like the following C code?
#include <stdio.h>
#include <dlfcn.h>
struct wl_display;
int main() {
struct wl_display* (*pwl_display_connect)(const char *name);
char* error;
void* handle = dlopen("/usr/lib/libwayland-client.so", RTLD_LAZY);
if(!handle) {
fprintf(stderr, "Error opening lib: %s\n", dlerror());
exit(1);
}
pwl_display_connect = dlsym(handle, "wl_display_connect");
if(!pwl_display_connect) {
fprintf(stderr, "Error loading function: %s\n", dlerror());
exit(1);
}
if(dlclose(handle) < 0) {
fprintf(stderr, "Error closing lib: %s\n", dlerror());
exit(1);
}
return 0;
}
compiled with
clang -o test test.c -ldl
Or will it translate into something like use clang <other stuff> -lwayland-core? Or am I completely wrong and headed in the wrong direction?
Below is the only documentation I read by reading the Rust Reference
link - , . link kind : dylib, static framework.
Edit: