I haven't been able to make calling D from C on Mac OS 10.9 work. I tried the following simple example:

foo.d

import std.stdio;

extern(C) int add(int x, int y){
    return x + y;
}

bar.c

#include <stdio.h>

int add(int , int);

int main(){

    int x = 1;
    int y = 2;

    char s[] = "%d + %d = %d";
    printf(s, x, y, add(x,y));
}

bash calls:
dmd -c foo.d
gcc bar.c foo.o

This gives a long error, summarized as
ld: symbol(s) not found for architecture x86_64

(FYI, in Mac OS 10.9 the aging gcc version has apparently been replaced with a more recent version of clang, so the above gcc call is actually some version of clang:

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix)

Is there some way to make this work? I'd like to call D code from C, and I'm fine statically compiling the D code and linking it to C.

Reply via email to