[C++-sig] ImportError: timemodule.so

RICH JOHNSON richjohnson905 at msn.com
Tue Aug 15 22:30:07 CEST 2006


Hi Rich,

When you get the following error at runtime on a unix system:

Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: /usr/lib/python2.2/lib-dynload/timemodule.so: undefined symbol:
PyDict_SetItemString

it is possible that you may need to use the -export-dynamic -Xlinker flag.

See http://docs.python.org/ext/link-reqs.html for more information.

----Original Message Follows----
From: "RICH JOHNSON" <richjohnson905 at msn.com>
Reply-To: Development of Python/C++ integration <c++-sig at python.org>
To: c++-sig at python.org
Subject: [C++-sig] ImportError: timemodule.so
Date: Mon, 07 Aug 2006 08:07:17 -0500

I am new to boost python and am having difficulty importing python modules
into a little C++ program.  Any insight into the problem would be
appreciated.

OS: Linux Redhat
gcc: 3.2.3
python 2.2
boost 1.33.1

 >From the command line I can do:
[rjohnson at pitwar7 rjohnson]$ python
Python 2.2.3 (#1, Feb 15 2005, 02:41:06)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>>from time import time,ctime
 >>>print 'Today is', ctime(time())
Today is Fri Aug  4 10:47:20 2006
 >>>

But the C++ program below outputs:
25
20
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: /usr/lib/python2.2/lib-dynload/timemodule.so: undefined symbol:
PyDict_SetItemString


#include <boost/python.hpp>
#include <iostream>

int main(int, char **)
{
using namespace boost::python;

Py_Initialize();

try
{
   PyRun_SimpleString("result = 5 ** 2");
      object module((handle<>(borrowed(PyImport_AddModule("__main__")))));
   object dictionary = module.attr("__dict__");
   object result = dictionary["result"];
   int result_value = extract<int>(result);
      std::cout << result_value << std::endl;
      dictionary["result"] = 20;

   PyRun_SimpleString("print result");

   // Here is the same command that ran successfully at the command line
above but fails from  C++
   PyRun_SimpleString("from time import time,ctime\n"
                    "print 'Today is',ctime(time())\n");
}
catch (error_already_set)
{
   PyErr_Print();
}

Py_Finalize();
return 0;
}

My LD_LIBRARY_PATH is /usr/local/lib:/usr/lib/python2.2/config
PYTHONPATH is /usr/lib/python2.2/config


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list