Sorry for any duplication, but this should be visible by now (I think).
-----Original Message----- From: Schwab,Wilhelm K Sent: Friday, April 02, 2010 7:24 AM To: [email protected]; [email protected] Subject: dlopen: I'm stumped Hello all, Attached is my attempt at calling dlopen() from Pharo, and it is not going well. The C code below works as expected, so the problem has to be either in my code or something in Pharo or the VM itself. I am fairly certain that loading the attached is safe, but DynamicLinkingLibrary getProcAddress:'cos' from:'libm.so'. crashes the vm in my experience. Any ideas? Bill /* http://www.unix.com/man-page/All/3/dlopen/ Build as: gcc -rdynamic -o fubar fubar.c -ldl */ #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> int main(int argc, char **argv) { void *handle; double (*cosine)(double); char *error; handle = dlopen("libm.so", RTLD_LAZY); if (!handle) { fprintf(stderr, "%s\n", dlerror()); exit(EXIT_FAILURE); } dlerror(); /* Clear any existing error */ /* Writing: cosine = (double (*)(double)) dlsym(handle, "cos"); would seem more natural, but the C99 standard leaves casting from "void *" to a function pointer undefined. The assignment used below is the POSIX.1-2003 (Technical Corrigendum 1) workaround; see the Rationale for the POSIX specification of dlsym(). */ *(void **) (&cosine) = dlsym(handle, "cos"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(EXIT_FAILURE); } printf("%f\n", (*cosine)(2.0)); dlclose(handle); exit(EXIT_SUCCESS); }
DynamicLinkingLibrary.st
Description: DynamicLinkingLibrary.st
_______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
