using pragma to link to gcc-compiled c library

Felix Klein coogabooga at hotmail.com
Tue Jun 5 17:33:36 PDT 2012


hi,

i'm having a hard time linking a c function into d.  i've looked 
at many posts about this, but can't seem to get it to work.  at 
the moment i'm trying to use pragma in the d source to help dmd 
find the function.  unfortunately the linker can't find it.

felix at mojo:~/d/misc$ cat ctest.d
import std.stdio;
pragma(lib, "/home/felix/d/misc/libcadder.a");

void
main()
{

   extern (C) int addem (int, int);

   int a=2, b=3;

   int c = addem(a,b);

   writeln("c=",c);
}
felix at mojo:~/d/misc$ cat cadder.c
int
addem(int a, int b)
{
   return (a+b);
}
felix at mojo:~/d/misc$ gcc -c cadder.c -o cadder.o
felix at mojo:~/d/misc$ ar rcs libcadder.a cadder.o
felix at mojo:~/d/misc$ dmd ctest.d
ctest.o: In function `_Dmain':
ctest.d:(.text._Dmain+0x18): undefined reference to 
`_D5ctest4mainFZv5addemMUiiZi'
collect2: ld returned 1 exit status
--- errorlevel 1
felix at mojo:~/d/misc$


More information about the Digitalmars-d-learn mailing list