loading D into R in OSX. Dynamic libraries problem
Jacob Carlborg
doob at me.com
Sat Jun 26 04:06:44 PDT 2010
On 2010-06-26 11:59, Michael wrote:
> I'm probably trying to complicate things too much while not really
> understanding what I'm doing... I want to be able to call D code from R. (R is
> a language for doing statistics)
> When I try to load the code, I get an error:
> dlopen( PATH/test.so, 6): Symbol not found: __minfo_beg
>
> what I did is the following: I have a small D program:
> --
> import tango.io.Stdout;
> extern (C) void Dfunc()
> {
> Stdout("got to D").newline ;
> }
> --
> I compile it with
> dmd -fPIC -c test.d
> then I make it into a dynamic library:
> R CMD SHLIB /usr/local/lib/libtango-user-dmd.a
> /usr/local/lib/libtango-base-dmd-d.a test.o
> which calls:
> gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names
> -mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module
> -multiply_defined suppress -L/usr/local/lib -o test.so test.o
> /usr/local/lib/libtango-user-dmd.a /usr/local/lib/libtango-base-dmd-d.a
> -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
> -Wl,CoreFoundation
>
> then I load the dynamic library into R, and get the above error.
> dyn.load("test.so")
>
> The equivalent in C works well:
> --
> #include<stdio.h>
> void test()
> {
> printf("got to C\n") ;
> }
> --
> gcc -fPIC -c test.c
> R CMD SHLIB test.o
> which calls:
> gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names
> -mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module
> -multiply_defined suppress -L/usr/local/lib -o test.so test.o
> -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
> -Wl,CoreFoundation
>
> At this point loading the resulting dynamic library from R causes no problems.
>
> What am I doing wrong, other than trying to complicate things?
First, have you built Tango as a dynamic library, using "bob" with the
"-d" flag? Oh I see now that you use an older version of Tango. Download
the latest version from trunk and use "bob" with the "-d" flag to build
Tango as a dynamic library. Then you should be able to build dynamic
libraries. BTW the "-fPIC" flag is not necessary on Mac, it's on by default.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list