在OS X上初始化D运行时 [英] Initializing the D runtime on OS X

查看:105
本文介绍了在OS X上初始化D运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个长期存在的问题,没有迫在眉睫的解决方案: 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

this seems to be a longrunning issue with no imminent solution: 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

在c程序中加载的d dylib中启动d运行时似乎存在问题.每当我调用Runtime.initialize()时,我都会遇到段错误.

There seems to be a problem with starting the d runtime in a d dylib loaded in a c program. Whenever I call Runtime.initialize() i get a 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编译,没有标志.

compiled with gcc, no flags.

d代码:

import core.runtime;

extern(C) int number() {
    Runtime.initialize();
    return(4);
}

使用dmd -shared编译

compiled with 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中完成的所有编译和调试

All compilation and debugging done in OS X 10.7

注意:如果Runtime.initialize();行被注释掉,库已加载并正确运行.

Note: if the Runtime.initialize(); line is commented out, the library is loaded and runs correctly.

推荐答案

现在已从github的最新druntime中修复了此问题

This is now fixed in the latest druntime from github

这篇关于在OS X上初始化D运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆