1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

dl: add get_libname function (#8909)

This commit is contained in:
StunxFS 2021-02-23 03:46:28 -04:00 committed by GitHub
parent fd59182659
commit fcc2094719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View File

@ -7,6 +7,7 @@ pub const (
// get_shared_library_extension returns the platform dependent shared library extension
// i.e. .dll on windows, .so on most unixes, .dylib on macos.
[inline]
pub fn get_shared_library_extension() string {
mut res := '.so'
$if macos {
@ -17,3 +18,10 @@ pub fn get_shared_library_extension() string {
}
return res
}
// get_libname returns a library name with the operating system specific extension for
// shared libraries.
[inline]
pub fn get_libname(libname string) string {
return '$libname$dl.dl_ext'
}

View File

@ -1,6 +1,7 @@
module dl
#include <dlfcn.h>
pub const (
rtld_now = C.RTLD_NOW
rtld_lazy = C.RTLD_LAZY

View File

@ -6,7 +6,7 @@ import dl
type FNAdder = fn (int, int) int
fn main() {
library_file_path := os.join_path(os.getwd(), 'library$dl.dl_ext')
library_file_path := os.join_path(os.getwd(), dl.get_libname('library'))
handle := dl.open(library_file_path, dl.rtld_lazy)
eprintln('handle: ${ptr_str(handle)}')
mut f := &FNAdder(0)

View File

@ -7,7 +7,7 @@ const (
vexe = os.real_path(os.getenv('VEXE'))
cfolder = os.dir(@FILE)
so_ext = dl.dl_ext
library_file_name = os.join_path(cfolder, 'library$so_ext')
library_file_name = os.join_path(cfolder, dl.get_libname('library'))
)
fn test_vexe() {