Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ python 3 binding

Tags:

c++

python

I am trying to bind python3 in C++.

When using this:

Py_SetProgramName(argv[0]);

it gives this error:

error C2664: 'Py_SetProgramName' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

Even though that's how the documentation example shows to do it.

I also tried this:

Py_SetProgramName((wchar_t*)argv[0]);

But apparently that's the wrong way to do it.

So how do I fix this, and is there any other good resources on binding Python 3 in C++?

like image 957
Neros Avatar asked Aug 15 '13 07:08

Neros


1 Answers

The official way of converting from char to wchar_t is now :

wchar_t *program = Py_DecodeLocale(argv[0], NULL);
Py_SetProgramName(program);

on a side note mbstowcs is not reliable on some platforms.

A quite good example of using python2/3 with c++ would be Panda3D. a c++ game engine scripted with python, that also provides a c++ module builder.

like image 177
Pmp P. Avatar answered Sep 18 '22 17:09

Pmp P.