편집 : http://d.puremagic.com/issues/show_bug.cgi?id=8133 http://www.digitalmars.com/d/archives/digitalmars/D/Ideas_for_runtime_loading_of_shared_libraries._154126.html http://lists.puremagic.com/pipermail/dmd-internals/2011-December/002853.html는 OS의 X에 D 런타임을 초기화
가로드 광고 dylib에서 D 런타임을 시작하기에 문제가 발생한 것 같습니다 :이 절박한 솔루션과 longrunning 문제가 될 것 같다 교류 프로그램. 내가 Runtime.initialize()를 호출 할 때마다 segfault가 생깁니다.
C 코드 :
#include <stdio.h>
#include <dlfcn.h>
int main() {
void *library;
int (*fptr)();
library = dlopen("testlib.dylib", RTLD_LAZY);
if(library == NULL)
puts("couldn't load the library");
else {
*(void **)(&fptr) = dlsym(library,"number");
if(fptr == NULL) {
puts("couldn't load function");
}
else {
printf("the result is %d\n",(*fptr)());
}
}
return(0);
}
GCC, 플래그없이 컴파일.
D 번호 :
import core.runtime;
extern(C) int number() {
Runtime.initialize();
return(4);
}
DMD 컴파일은
역 추적을
를 -shared :Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x000000010003de28 in __tls_get_addr()
(gdb) bt
#0 0x000000010003de28 in __tls_get_addr()
#1 0x000000010003cdfc in thread_attachThis()
#2 0x000000010003ccb8 in thread_init()
#3 0x000000010003e312 in gc_init()
#4 0x0000000100044ff5 in rt_init()
#5 0x000000010003b637 in D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb()
#6 0x0000000100034ee9 in number()
#7 0x0000000100000e84 in main()
OS X 10.7
주의 할 모든 컴파일 및 디버깅 : 런타임 만약 .initialize(); 행이 주석 처리되면 라이브러리가로드되어 올바르게 실행됩니다.