Hello all! I am having trouble with using a c++ shared object file with D. I am running Linux Mint 32 bit. I am using the 32 bit version of DMD. For some reason any extra variables I pass to the C++ function have the value 0.
Even when I specifically pass it something else.

------------------------------------------------

D source:

import core.stdc.stdio;
import core.stdc.stdlib;
import core.sys.posix.dlfcn;

int main() {

        void *lh = dlopen("libdll.so", RTLD_LAZY);

extern(C) long function(long y, long x) fn = cast(long function(long y, long x))dlsym(lh, "dll");

        fn(1, 71);

        return 0;
}

C++ source:

#include <stdio.h>

extern "C" long dll(long y, long x) {
        
        if(y == 0){
                //int myint = (int) x;
        //      printf("%c", myint);
                printf("test1: ");
                printf("%ld", x);
        }
        else if(y == 1){
                printf("test2: ");
                printf("%ld", x);
        }
        else if(y == 2){
                printf("test3: ");
                //return getchar();
        }
  return 0;
}

Compile script:

g++ -c dll.cpp -fpic
g++ -shared -o libdll.so dll.o

dmd -c main.d
dmd main.o -L-ldl -L-rpath=.
./main

-------------------------------

Does anyone here know why this is the case, or how I can fix it?
Thanks!

Reply via email to