@@ -26,19 +26,24 @@ JL_DLLEXPORT char * __cdecl dirname(char *);
26
26
#else
27
27
#include <libgen.h>
28
28
#endif
29
+ #ifndef _OS_WINDOWS_
30
+ #include <dlfcn.h>
31
+ #endif
29
32
30
- JL_DLLEXPORT int jl_is_initialized (void ) { return jl_main_module != NULL ; }
33
+ JL_DLLEXPORT int jl_is_initialized (void )
34
+ {
35
+ return jl_main_module != NULL ;
36
+ }
31
37
32
- // First argument is the usr/lib directory where libjulia is, or NULL to guess.
33
- // if that doesn't work, try the full path to the "lib" directory that
34
- // contains lib/julia/sys.ji
38
+ // First argument is the usr/bin directory where the julia binary is, or NULL to guess.
35
39
// Second argument is the path of a system image file (*.ji) relative to the
36
- // first argument path, or relative to the default julia home dir. The default
37
- // is something like ../lib/julia/sys.ji
40
+ // first argument path, or relative to the default julia home dir.
41
+ // The default is something like ../lib/julia/sys.ji
38
42
JL_DLLEXPORT void jl_init_with_image (const char * julia_home_dir ,
39
43
const char * image_relative_path )
40
44
{
41
- if (jl_is_initialized ()) return ;
45
+ if (jl_is_initialized ())
46
+ return ;
42
47
libsupport_init ();
43
48
jl_options .julia_home = julia_home_dir ;
44
49
if (image_relative_path != NULL )
@@ -51,17 +56,30 @@ JL_DLLEXPORT void jl_init_with_image(const char *julia_home_dir,
51
56
52
57
JL_DLLEXPORT void jl_init (void )
53
58
{
54
- char * libjldir = NULL ;
55
-
59
+ char * libbindir = NULL ;
60
+ #ifdef _OS_WINDOWS_
56
61
void * hdl = (void * )jl_load_dynamic_library_e (NULL , JL_RTLD_DEFAULT );
57
- if (hdl )
58
- libjldir = dirname ((char * )jl_pathname_for_handle (hdl ));
59
- if (libjldir )
60
- jl_init_with_image (libjldir , jl_get_default_sysimg_path ());
61
- else {
62
+ if (hdl ) {
63
+ char * to_free = (char * )jl_pathname_for_handle (hdl );
64
+ if (to_free ) {
65
+ libbindir = strdup (dirname (to_free ));
66
+ free (to_free );
67
+ }
68
+ }
69
+ #else
70
+ Dl_info dlinfo ;
71
+ if (dladdr ((void * )jl_init , & dlinfo ) != 0 && dlinfo .dli_fname ) {
72
+ char * to_free = strdup (dlinfo .dli_fname );
73
+ (void )asprintf (& libbindir , "%s" PATHSEPSTRING ".." PATHSEPSTRING "%s" , dirname (to_free ), "bin" );
74
+ free (to_free );
75
+ }
76
+ #endif
77
+ if (!libbindir ) {
62
78
printf ("jl_init unable to find libjulia!\n" );
63
79
abort ();
64
80
}
81
+ jl_init_with_image (libbindir , jl_get_default_sysimg_path ());
82
+ free (libbindir );
65
83
}
66
84
67
85
JL_DLLEXPORT jl_value_t * jl_eval_string (const char * str )
0 commit comments