|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - Calling D function from C
Is there a way to compile a D object file with some C code? I am looking into
creating a PHP extension from D instead of C and as I see it, I would need to
be
able to create and interface function in C that can call a D function.
I tried a simple example of this, but ran into some linking problems. The
example follows:
------------- D code -----------------
import std.stdio;
extern (C)
{
void test()
{
test2();
}
} //end extern
void test2()
{
writefln("test");
}
------------- C code -------------------
#include <stdio.h>
void test();
int main(int argc, char* argv[])
{
test();
return 0;
}
------------ Compiled As ---------------
/opt/dmd/bin/dmd test.d -c
gcc main.c test.o -m32 -o tester -lphobos -lpthread -lm
Linker Error...
Apr 22 2008
Jonathan Crapuchettes wrote: Apr 22 2008
On Wed, 23 Apr 2008 07:36:26 +0100, Johan Granberg <lijat.meREM OVEgmail.com> wrote:Jonathan Crapuchettes wrote: Apr 23 2008
I tried both gdc and dmd for the D code and both had gcc create the same linker errors. Thanks JC Bruce Adams wrote:On Wed, 23 Apr 2008 07:36:26 +0100, Johan Granberg <lijat.meREM OVEgmail.com> wrote:Jonathan Crapuchettes wrote: Apr 23 2008
Jonathan Crapuchettes wrote:Is there a way to compile a D object file with some C code? I am looking into creating a PHP extension from D instead of C and as I see it, I would need to be able to create and interface function in C that can call a D function. Apr 23 2008
"Jonathan Crapuchettes" <jcrapuchettes gmail.com> wrote in message news:fulp5j$19hu$1 digitalmars.com.../opt/dmd/bin/dmd test.d -c gcc main.c test.o -m32 -o tester -lphobos -lpthread -lm Linker Error... Apr 23 2008
/usr/lib/gcc/x86_64-linux-gnu/4.1.3/../../../../lib32/libphobos.a(deh2.o): In function `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable': internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14): undefined reference to `_deh_end' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): undefined reference to `_deh_end' collect2: ld returned 1 exit status Jarrett Billingsley wrote:"Jonathan Crapuchettes" <jcrapuchettes gmail.com> wrote in message news:fulp5j$19hu$1 digitalmars.com.../opt/dmd/bin/dmd test.d -c gcc main.c test.o -m32 -o tester -lphobos -lpthread -lm Linker Error... Apr 23 2008
Jonathan Crapuchettes wrote:/usr/lib/gcc/x86_64-linux-gnu/4.1.3/../../../../lib32/libphobos.a(deh2.o): In function `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable': internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14): undefined reference to `_deh_end' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): undefined reference to `_deh_end' collect2: ld returned 1 exit status Jarrett Billingsley wrote:"Jonathan Crapuchettes" <jcrapuchettes gmail.com> wrote in message news:fulp5j$19hu$1 digitalmars.com.../opt/dmd/bin/dmd test.d -c gcc main.c test.o -m32 -o tester -lphobos -lpthread -lm Linker Error... Apr 23 2008
I got the same errors doing you suggestion. Thanks, JC gcc -c main.c -m32 jonathan blackbeard:~/workspace/c/ctodTest$ /opt/dmd/bin/dmd test.d main.o gcc test.o main.o -o test -m32 -Xlinker -L/opt/dmd/bin/../lib -lphobos -lpthread -lm Errors... BCS wrote:Jonathan Crapuchettes wrote:/usr/lib/gcc/x86_64-linux-gnu/4.1.3/../../../../lib32/libphobos.a(deh2.o): In function `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable': internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14): undefined reference to `_deh_end' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): undefined reference to `_deh_end' collect2: ld returned 1 exit status Jarrett Billingsley wrote:"Jonathan Crapuchettes" <jcrapuchettes gmail.com> wrote in message news:fulp5j$19hu$1 digitalmars.com.../opt/dmd/bin/dmd test.d -c gcc main.c test.o -m32 -o tester -lphobos -lpthread -lm Linker Error... Apr 23 2008
I just tried the following and it worked. gcc -c main.c gdmd test.d main.o Thanks for everyones help! JC BCS wrote:Jonathan Crapuchettes wrote:/usr/lib/gcc/x86_64-linux-gnu/4.1.3/../../../../lib32/libphobos.a(deh2.o): In function `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable': internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe): undefined reference to `_deh_beg' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14): undefined reference to `_deh_end' internal/deh2.d:(.text._D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37): undefined reference to `_deh_end' collect2: ld returned 1 exit status Jarrett Billingsley wrote:"Jonathan Crapuchettes" <jcrapuchettes gmail.com> wrote in message news:fulp5j$19hu$1 digitalmars.com.../opt/dmd/bin/dmd test.d -c gcc main.c test.o -m32 -o tester -lphobos -lpthread -lm Linker Error... Apr 23 2008
|