cygwinでdll
ここを参考にcygwinでdllのテストをやってみる。
dllsrc.c
#include <stdio.h> void hello() { puts("hello."); }
$ gcc -shared dllsrc.c -o cygtest.dll $ mkdir dll $ mv cygtest.dll dll
main.c
#include <stdio.h> #include <dlfcn.h> int main(void) { void *handle; void (*func)(); char *err; /* cygtest.dll の動的ロード。拡張子「dll」はなくとも構わない。*/ handle = dlopen("cygtest", RTLD_LAZY); if (!handle) { fprintf (stderr, "%s\n", dlerror()); return 1; } /* dlopen() によって取得した cygtest.dll のハンドルから、 関数「hello」へのポインタを取得する。*/ func = dlsym(handle, "hello"); if ((err = dlerror()) != NULL) { fprintf(stderr, "%s\n", err); return 1; } /* 関数「hello」を実行 */ func(); /* cygtest.dll のハンドルをクローズ。*/ dlclose(handle); return 0; }
$ gcc main.c $ ./a.exe No such file or directory
$ LD_LIBRARY_PATH=~/tmp/dll ./a.exe hello.