Initialization problem of shared library in HP-UX11

gother flz at cfdrc.com
Mon Apr 1 12:29:48 EST 2002


I got into the following situation in the HP machine with gcc 3.0.3
compiler

myStr.h
-----------------
class MyStr
{

public: 
  char * str;
  Mystr();
  MyStr(const char *);
  MyStr& operator=(const char *);
}
=====================================
Var.h
----------
extern MyStr mystr;
extern int myint;
=====================================
var.cpp
---------------
MyStr mystr = "xyz";
int myint = 1;
====================================
myPrint.h
---------------
extern void f();
===================================
myPrint.cpp
---------------
...
void f()
{
  printf("%x\n",mystr.str);
  printf("%d\n",myint);
}
==================================


Made those available to python by Swig

MyTest.i
----------------
%module MyTest
%{
#include "Var.h"
#include "myStr.h"
#include myPrint.h
%}
%include myPrint.h


The problem is the global variable (user defined class) "mystr" never
initialized when I import the shared library into python, but int
global variable is properly initialized.

When I linked the shared library to a main function, user defined
class variable "mystr" got properly intialized.

Anybody know how to resolve this problem?

Thanks

Gother



More information about the Python-list mailing list