[CIG-SHORT] adding a static library
Brad Aagaard
baagaard at usgs.gov
Sat Apr 7 20:13:51 PDT 2012
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