Created
April 14, 2011 21:52
-
-
Save ProjectMoon/920648 to your computer and use it in GitHub Desktop.
Files illustrating simple attempt at making a D shared library with GDC.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <dlfcn.h> | |
#include <stdlib.h> | |
void main() { | |
void (*hiD)(void); | |
void* handle = dlopen("./libtest.so", RTLD_LAZY); | |
if (handle == NULL) { | |
printf("%s\n", dlerror()); | |
exit(1); | |
} | |
hiD = dlsym(handle, "hiD"); | |
if (hiD != NULL) { | |
hiD(); | |
} | |
else { | |
printf("hiD is null\n"); | |
} | |
dlclose(handle); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import std.c.linux.linux; | |
import std.string; | |
extern (C) void perror(char* s); | |
extern (C) void exit(int status); | |
extern (C) char* dlerror(); | |
void main() | |
{ | |
void* handle = dlopen("./libtest.so\0".ptr, RTLD_LAZY); | |
if (handle == null) { | |
printf("%s\n", dlerror()); | |
exit(1); | |
} | |
void function() hiD = cast(void function()) dlsym(handle, ("hiD").ptr); | |
if (hiD != null) { | |
hiD(); | |
} | |
else { writeln("hiD is null"); } | |
dlclose(handle); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void hiD() { | |
printf("hi from c\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
extern (C) void hiD() { | |
writeln("hi from D lib"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've tried this several ways. Currently, I'm trying to dlopen() the D version of libtest.so from the C version of main:
I receive the following error:
cannot allocate memory in static TLS block