[CIG-SHORT] adding a static library
Birendra jha
bjha7333 at yahoo.com
Mon Apr 9 09:58:18 PDT 2012
Brad,
So can I link Pylith to a static library? I am sorry for this confusion but I still didn't understand. I don't want to create static modules of pylith such as _problemsmodules.a, I just want to call a function present in an external static library. Where do I supply this external library i.e. which Makefile.am?
So far I was editing build/pylith/pylith-1.6.3/libsrc/pylith/Makefile.am
libpylith_la_LDFLAGS = $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS) \
-Wl,-rpath -Wl,$(MATVEC)/lib -L$(MATVEC)/lib
INCLUDES += -I$(MATVEC)/include
libpylith_la_LIBADD += -lmatvec
where libmatvec.a is a static library. Paths are correct.
I get make error:
-Wl,-soname -Wl,libpylith.so.0 -o .libs/libpylith.so.0.0.0
/usr/bin/ld: /home/user/GPRS08/LIBS/Libs/libGPRSLinear.a(GlobalCPRPre.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/home/user/GPRS08/LIBS/Libs/libGPRSLinear.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[4]: *** [libpylith.la] Error 1
make[4]: Leaving directory `/home/user/build/pylith/pylith-build/libsrc/pylith'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/user/build/pylith/pylith-build/libsrc/pylith'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/user/build/pylith/pylith-build/libsrc'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/user/build/pylith/pylith-build'
make: *** [all] Error 2
Note I tried this with a shared library (Test below) and it works. Of course, I don't have shared library or source code of the matvec library that I am interested in combining with Pylith.
Thanks
Birendra
--- On Sun, 4/8/12, Brad Aagaard <baagaard at usgs.gov> wrote:
> From: Brad Aagaard <baagaard at usgs.gov>
> Subject: Re: adding a static library
> To: "Birendra jha" <bjha7333 at yahoo.com>
> Cc: cig-short at geodynamics.org
> Date: Sunday, April 8, 2012, 8:43 AM
> Birendra,
>
> The Python modules must be shared, because they are loaded
> at runtime
> from Python. This means that trying to generate
> _problemsmodule.a will
> never work. If you are customizing PyLith so that it needs
> an additional
> library, then you must call the routine from the code in the
> Pylith
> library and then add the external library to the link line.
> You can
> verify if symbols are just referenced or referenced and
> resolved by
> using the unix nm tool on the library. See the nm
> documentation for more
> details.
>
> Brad
>
>
>
> On 4/7/12 11:07 AM, Birendra jha wrote:
> > Hi developers,
> >
> > I am trying to compile and install Pylith using a very
> simple static library.
> > //Test.cpp
> > #include "Test.h"
> > #include<cstdio>
> > #include<iostream>
> > using namespace std;
> > Test::Test()
> > {
> > x = 210;
> > }
> >
> > int Test::add(int a, int b)
> > {
> > cout<<x<<endl;
> > return a+b;
> > }
> >
> > Test::~Test()
> > {
> > }
> > //Test.h
> > #if !defined(Test_h)
> > #define Test_h
> > class Test
> > {
> > public:
> > Test();
> > ~Test();
> > int add(int,int);
> > private:
> > int x;
> > };
> > #endif
> >
> > Then g++ -c Test.cpp, then, ar crs libTest.a Test.o
> > I placed libTest.a in $HOME/pylith/lib. I added the
> library in pylith-1.6.3/libsrc/pylith/Makefile.am
> > libpylith_la_LIBADD += -lTest
> > and put -static
> > libpylith_la_LDFLAGS = -static $(AM_LDFLAGS)
> $(PYTHON_LA_LDFLAGS)
> > I am trying to use it in the constructor of
> Formulation,
> > Test test;
> > int i;
> > i=test.add(20,3);
> > I include the Test.h in Formulation.cc.
> >
> > make,make install was fine. libpylith.a was created.
> But I get runtime error:
> > ImportError:
> /home/user/pylith/lib/python2.7/site-packages/pylith/problems/_problemsmodule.so:
> undefined symbol: _ZN4TestD1Ev
> >
> > I also tried adding the library in
> pylith-1.6.3/modulesrc/problems/Makefile.am with -static.
> This creates _problemsmodule.a but program still looks in
> _problemsmodule.so for Test symbols.
> >
> > Note, I can get this working for a shared library i.e.
> libTest.so
> > I don't know what I am missing for the static library.
> >
> > Can you please help me?
> >
> > Thanks and regards
> > Birendra
> >
>
>
More information about the CIG-SHORT
mailing list