0

I have compiled the python source code for 32bit and am trying to use the Py_Initialize() API to init the python interpreter in my C++ application.
Py_Initialize() leads to below crash. Please help me how to solve on this.

Am compiling my code like below:

g++ ./Pythoninterpreter.cpp -m32 -lpthread -ldl -lutil /usr/lib/libm.a /usr/lib/libpython2.7.a -Xlinker -export-dynamic -I/root/python_tar/Python-2.7.6/Include -I/root/python_tar/Python-2.7.6 -o pythonintepreter

gdb back trace
===============

#0  0x080e8ba7 in va_build_value (format=0x8152ec1 "", va=0xffed7564 "\240\344\027\b\244y\355\377", flags=0) at Python/modsupport.c:521
521         memcpy(lva, va, sizeof(va_list));
(gdb) bt
#0  0x080e8ba7 in va_build_value (format=0x8152ec1 "", va=0xffed7564 "\240\344\027\b\244y\355\377", flags=0) at Python/modsupport.c:521
#1  0x080e8ca6 in Py_BuildValue (format=0x8152ebe "[O]") at Python/modsupport.c:485
#2  0x080a77a7 in mro_implementation (type=0x817e4a0) at Objects/typeobject.c:1605
#3  0x080a3d68 in mro_internal (type=0x4) at Objects/typeobject.c:1636
#4  0x080a4723 in PyType_Ready (type=0x817e4a0) at Objects/typeobject.c:4057
#5  0x080a5186 in PyType_Ready (type=0x817e3c0) at Objects/typeobject.c:4005
#6  0x08088252 in _Py_ReadyTypes () at Objects/object.c:2071
#7  0x080ee3f4 in Py_InitializeEx (install_sigs=1) at Python/pythonrun.c:191
#8  0x080eee32 in Py_Initialize () at Python/pythonrun.c:382
#9  0x080598fe in PythonIntepretor::PythonIntepretor(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short) ()
#10 0x080595fe in main ()
(gdb)

1 Answer 1

2

I'm not entirely sure of what you want to do since you didn't provide the code on PythonInterpreter.cpp.

The following code compiles with the command line:

g++ -I/usr/include/python2.7/ -o foo foo.cpp -lpython2.7

#include  "Python.h"
int main()
{
  Py_Initialize();
  return 0;
}
Sign up to request clarification or add additional context in comments.

2 Comments

am just doing the same thing. But it crashes. And FYI, I have compiled the python source code for 32 bit architecture. With 64bit, even am able to run the code successfully
I compiled the python source code with 32bit architecture. the python binary produced as part of the compilation also throws the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.