Skip to content

Commit fcc2094

Browse files
authored
dl: add get_libname function (#8909)
1 parent fd59182 commit fcc2094

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

vlib/dl/dl.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub const (
77

88
// get_shared_library_extension returns the platform dependent shared library extension
99
// i.e. .dll on windows, .so on most unixes, .dylib on macos.
10+
[inline]
1011
pub fn get_shared_library_extension() string {
1112
mut res := '.so'
1213
$if macos {
@@ -17,3 +18,10 @@ pub fn get_shared_library_extension() string {
1718
}
1819
return res
1920
}
21+
22+
// get_libname returns a library name with the operating system specific extension for
23+
// shared libraries.
24+
[inline]
25+
pub fn get_libname(libname string) string {
26+
return '$libname$dl.dl_ext'
27+
}

vlib/dl/dl_nix.c.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module dl
22

33
#include <dlfcn.h>
4+
45
pub const (
56
rtld_now = C.RTLD_NOW
67
rtld_lazy = C.RTLD_LAZY

vlib/dl/example/use.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dl
66
type FNAdder = fn (int, int) int
77

88
fn main() {
9-
library_file_path := os.join_path(os.getwd(), 'library$dl.dl_ext')
9+
library_file_path := os.join_path(os.getwd(), dl.get_libname('library'))
1010
handle := dl.open(library_file_path, dl.rtld_lazy)
1111
eprintln('handle: ${ptr_str(handle)}')
1212
mut f := &FNAdder(0)

vlib/dl/example/use_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const (
77
vexe = os.real_path(os.getenv('VEXE'))
88
cfolder = os.dir(@FILE)
99
so_ext = dl.dl_ext
10-
library_file_name = os.join_path(cfolder, 'library$so_ext')
10+
library_file_name = os.join_path(cfolder, dl.get_libname('library'))
1111
)
1212

1313
fn test_vexe() {

0 commit comments

Comments
 (0)