提交 c7033436 编写于 作者: V Victor Cuadrado Juan 提交者: GitHub

Fix dynamic.c segmentation fault

Make dlopen() use cwd.

Without this fix the program will get a segmentation fault, as
dlopen() will return NULL, and dlerror() diagnoses:

    Failed to load fn.so: fn.so: cannot open shared object file: No such file or
    directory

man dlopen says:

    If filename contains a slash ("/"), then it is interpreted as a (relative or
    absolute) pathname (**what we want**). Otherwise, the dynamic linker
    searches for the object as follows… (*lists several options that don't for
    the cwd unless you set up env vars*)
上级 a245630c
......@@ -27,7 +27,7 @@ void compile_and_run(){
return;
}
void *handle = dlopen("fn.so", RTLD_LAZY);
void *handle = dlopen("./fn.so", RTLD_LAZY);
if (!handle) printf("Failed to load fn.so: %s\n", dlerror());
typedef double (*fn_type)(double);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册