@@ -59,8 +59,6 @@ static int endswith_extension(const char *path)
59
59
60
60
#define PATHBUF 4096
61
61
62
- extern char * julia_bindir ;
63
-
64
62
#define JL_RTLD (flags , FLAG ) (flags & JL_RTLD_ ## FLAG ? RTLD_ ## FLAG : 0)
65
63
66
64
#ifdef _OS_WINDOWS_
@@ -136,7 +134,7 @@ JL_DLLEXPORT int jl_dlclose(void *handle)
136
134
137
135
JL_DLLEXPORT void * jl_load_dynamic_library (const char * modname , unsigned flags , int throw_err )
138
136
{
139
- char path [PATHBUF ];
137
+ char path [PATHBUF ], relocated [ PATHBUF ] ;
140
138
int i ;
141
139
#ifdef _OS_WINDOWS_
142
140
int err ;
@@ -173,6 +171,9 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
173
171
this branch permutes all base paths in DL_LOAD_PATH with all extensions
174
172
note: skip when !jl_base_module to avoid UndefVarError(:DL_LOAD_PATH),
175
173
and also skip for absolute paths
174
+ We also do simple string replacement here for elements starting with `@executable_path/`.
175
+ While these exist as OS concepts on Darwin, we want to use them on other platforms
176
+ such as Windows, so we emulate them here.
176
177
*/
177
178
if (!abspath && jl_base_module != NULL ) {
178
179
jl_array_t * DL_LOAD_PATH = (jl_array_t * )jl_get_global (jl_base_module , jl_symbol ("DL_LOAD_PATH" ));
@@ -183,13 +184,21 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
183
184
size_t len = strlen (dl_path );
184
185
if (len == 0 )
185
186
continue ;
187
+
188
+ // Is this entry supposed to be relative to the bindir?
189
+ if (len >= 16 && strncmp (dl_path , "@executable_path" , 16 ) == 0 ) {
190
+ snprintf (relocated , PATHBUF , "%s%s" , jl_options .julia_bindir , dl_path + 16 );
191
+ len = len - 16 + strlen (jl_options .julia_bindir );
192
+ } else {
193
+ strncpy (relocated , dl_path , len );
194
+ }
186
195
for (i = 0 ; i < n_extensions ; i ++ ) {
187
196
const char * ext = extensions [i ];
188
197
path [0 ] = '\0' ;
189
- if (dl_path [len - 1 ] == PATHSEPSTRING [0 ])
190
- snprintf (path , PATHBUF , "%s%s%s" , dl_path , modname , ext );
198
+ if (relocated [len - 1 ] == PATHSEPSTRING [0 ])
199
+ snprintf (path , PATHBUF , "%s%s%s" , relocated , modname , ext );
191
200
else
192
- snprintf (path , PATHBUF , "%s" PATHSEPSTRING "%s%s" , dl_path , modname , ext );
201
+ snprintf (path , PATHBUF , "%s" PATHSEPSTRING "%s%s" , relocated , modname , ext );
193
202
#ifdef _OS_WINDOWS_
194
203
if (i == 0 ) { // LoadLibrary already tested the extensions, we just need to check the `stat` result
195
204
#endif
0 commit comments