Using static d libs in C++

Mike Wey no.spam at example.com
Sat Sep 29 03:05:06 PDT 2007


Chrono wrote:
> Hello!
> 
> I'm new to d. And I'd like to use some d functions in my c++ projects by
> building them static and linking them.
> 
> my platform: dmd and g++ on linux.
> 
> ####################### BEGIN sub.d: #######################
> import std.stdio;
> 
> extern (C) int testproc(int somevar)
> {
>         return (somevar + 1);
> }
> #######################  END  sub.d: #######################
> 
> ##################### BEGIN main.cpp : #####################
> #include <iostream>
> 
> extern "C" int testproc(int somevar);
> 
> int main(void)
> {
>   int myvar = 5;
>   printf("myvar: %d\n", testproc(myvar));
>   return 0;
> }
> #####################  END  main.cpp : #####################
> 
> 
> Compiling them wihout linking.
> ./dmd -c sub.d
> g++ -c main.cpp
> 
> everything works fine, I get main.o and sub.o but then
> 
> gcc main.o sub.o -o myprogram -m32 -lstdc++ -Xlinker -L./dmd/bin/../lib
> -lphobos -lpthread -lm
> 
> 
> 
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libphobos.a(deh2.o): In
> function `_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable':
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x9):
> undefined reference to `_deh_beg'
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0xe):
> undefined reference to `_deh_beg'
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x14):
> undefined reference to `_deh_end'
> internal/deh2.d:(.gnu.linkonce.t_D4deh213__eh_finddataFPvZPS4deh213DHandlerTable+0x37):
> undefined reference to `_deh_end'
> collect2: ld returned 1 exit status
> --- errorlevel 1
> 
> 
> 
> 
> any ideas?


It looks like gcc is looking for libphobos.a in: /usr/lib/libphobos.a 
while judging from what you use on the command line: -L./dmd/bin/../lib
it's not located there. try specifying the full path.


More information about the Digitalmars-d-learn mailing list