mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
dl: add a complete tested shared library generation/usage example
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
module dl
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
pub const (
|
||||
rtld_now = C.RTLD_NOW
|
||||
rtld_now = C.RTLD_NOW
|
||||
rtld_lazy = C.RTLD_LAZY
|
||||
dl_ext = '.so'
|
||||
dl_ext = get_shared_library_extension()
|
||||
)
|
||||
|
||||
fn C.dlopen(filename charptr, flags int) voidptr
|
||||
@@ -28,3 +27,14 @@ pub fn close(handle voidptr) bool {
|
||||
pub fn sym(handle voidptr, symbol string) voidptr {
|
||||
return C.dlsym(handle, symbol.str)
|
||||
}
|
||||
|
||||
pub fn get_shared_library_extension() string {
|
||||
mut res := '.so'
|
||||
$if macos {
|
||||
res = '.dylib'
|
||||
}
|
||||
$if windows {
|
||||
res = '.dll'
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user