[ADMB Users] DLLs

Mark Payne mpa at aqua.dtu.dk
Thu Apr 28 04:01:32 PDT 2011


Hi Dave,

Thanks for sending this around. I was wondering if could could please clarify the bit about recompliling ADMB with the -fPIC flag please? I recompiled ADMB, adding -fPIC as a linkerflag to the configuration script:

./configure BUILD_64BIT=yes LDFLAGS=-fPIC

But I see get an error at linking time about this:

[mpayne at oleander tadf]$ admb -d bimix

*** tpl2cpp -dll bimix

*** adcomp -d bimix
g++ -c -O3 -Wno-deprecated -D__GNUDOS__ -DBUILDING_DLL -Dlinux -DOPT_LIB -DUSE_LAPLACE -fpermissive -I. -I/home/mpayne/Software/admb/admb/include bimix.cpp
bimix.cpp: In function ‘void bimix(int*, double*, double*, double*, double*, double*, double*, double*, double*, double*, char**)’:
bimix.cpp:128: warning: deprecated conversion from string constant to ‘char*’

*** adlink -d bimix
g++ -s -shared -L/home/mpayne/Software/admb/admb/lib bimix.o -ldf1b2o -ladmod -ladt -lado -ldf1b2o -ladmod -ladt -lado -o bimix.so
/usr/bin/ld: bimix.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
bimix.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

Error: could not create bimix.so

Where should the -fPIC flag be set?

Best wishes,

Mark

-----Original Message-----
From: users-bounces at admb-project.org on behalf of dave fournier
Sent: Wed 4/27/2011 9:05 PM
To: users at admb-project.org
Subject: Re: [ADMB Users] DLLs
 
I thought it might be interesting to revisit this.  I used the example 
bimix.tpl from the manual.
I have attached the tpl file the data and the R script. this is for linux.
It is a crummy data example I just made up.

you create the cpp and htp files with the command

    tpl2cpp -dll bimix

Now you want to compile to a shared library.  This is a lot easier than 
it used to be.
first you need to rebuild admb-10.1 adding the -fPIC option for the 
compiler.

Here is my script to compile bimix.cpp and produce a shared library
named bimix.so


ADMB_HOME=/dave2/admb-10.1/build/admb-10.1-linux-gcc4.4.5-64bit/admb-10.1-linux-gcc4.4.5-64bit

g++  --shared  -fPIC -ggdb -w -fpermissive  -DUSE_LAPLACE -Dlinux 
-D__GNUDOS__ -o$1.so $1.cpp \
   -I. -I${ADMB_HOME}/include \
   -L${ADMB_HOME}/lib \
   -ladt -lads -ladmod -ldf1b2s -ladt -lads -ladmod -ldf1b2s \
   -ladt -lads -ladmod -ldf1b2s -ladt -lads -ladmod -ldf1b2s


under R this is loaded with the command

    dyn.load("bimix.so")


To run the example in R you type

    source("bimix.r")

and it all just works for me.


This all seems to work and it works when I call the routine twice as in 
the R script.

So maybe this is not too hard





More information about the Users mailing list