Method: RCSimCinterface.rcsim_load_c

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

.rcsim_load_c(codeV, libnameV, funcnameV) ⇒ Object

Loads a C program dynamic library (called from HDLRuby) for a code.



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 478

VALUE rcsim_load_c(VALUE mod, VALUE codeV, VALUE libnameV, VALUE funcnameV) {
    char* libname;
    char* funcname;
    Code code;
    void* handle;

    libname  = StringValueCStr(libnameV);
    funcname = StringValueCStr(funcnameV);
   
    /* Get the code. */ 
    value_to_rcsim(CodeS,codeV,code);
    /* Load the library. */
    handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL);
    if (handle == NULL) {
        fprintf(stderr,"Unable to open program: %s\n",dlerror());
        exit(-1);
    }
    code->function = dlsym(handle,funcname);
    if (code->function == NULL) {
        fprintf(stderr,"Unable to get function: %s\n",code->name);
        exit(-1);
    }
    return codeV;
}