[CIG-SHORT] adding a static library

Birendra jha bjha7333 at yahoo.com
Sat Apr 7 11:07:55 PDT 2012


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