1
0
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:
Delyan Angelov
2020-12-15 18:22:07 +02:00
parent e3a1756b11
commit 3a9034a0d0
6 changed files with 105 additions and 23 deletions

View File

@@ -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
}