日期:2014-05-16 浏览次数:21000 次
#include <Python.h>
CServerAssist::CServerAssist(void)
{
}
CServerAssist::~CServerAssist(void)
{
}
...
...
CServerAssist::EmLoginCode CServerAssist::ExecutePython(
const std::string& strModuleName, const std::string& strFunName, const defVecPythonParmsArr& strArrParm ) const
{
Py_Initialize();
#if defined(_MSC_VER)
// Microsoft
#elif defined(_GCC)
// GCC
PyRun_SimpleString("import sys");
PyRun_SimpleString(GetScriptToInputPythonPath().c_str());
PyRun_SimpleString("import os");
PyRun_SimpleString("import string");
#else
#pragma warning Unknown platform
#endif
PyObject* pModule = NULL;
PyObject* pFuc = NULL;
pModule = PyImport_ImportModule(strModuleName.c_str());
pFuc = PyObject_GetAttrString(pModule, strFunName.c_str());
PyObject* pArgs = PyTuple_New(static_cast<int>(strArrParm.size()));
int iCurPosOfParm = 0;
defPairOnePythonParm onePythonParm;
defVecPythonParmsArr::const_iterator iter = strArrParm.begin();
for ( ; iter!= strArrParm.end(); ++iter, ++iCurPosOfParm )
{
onePythonParm = *iter;
PyTuple_SetItem(
pArgs,
iCurPosOfParm,
Py_BuildValue( onePythonParm.first.c_str(), onePythonParm.second.c_str() ) );
}
PyObject* pReturn = NULL;
pReturn = PyEval_CallObject(pFuc, pArgs);
Py_Finalize();
// Code??àí
return CServerAssist::emValid;
}
std::string CServerAssist::GetScriptToInputPythonPath() const
{
std::string strScript = "sys.path.append('";
strScript += GetPathOfPythonScript();
strScript += "')";
return strScript;
}
std::string CServerAssist::GetPathOfPythonScript() const
{
#if defined(_MSC_VER)
// Microsoft
return "D:\\cocos2d-x-2.1.5\\projects\\CityPlusPlus\\Classes\\dist";
#elif defined(_GCC)
// GCC
return "./../dist/";
#else
#pragma warning Unknown platform
return "";
#endif
return "";
}
: sudo g++ -I/usr/include/python2.7 CServeAssist.cpp -fPIC -shared -o libExtAssist.so -L/usr/lib -lpython2.7
Android NDK: WARNING:jni/Android.mk:cocos2dcpp_shared: non-system libraries in linker flags: -lpython2.7
warning: skipping incompatible /usr/lib/libpython2.7.so while searching for python2.7
arm-linux-androideabi/bin/ld: error: cannot find -lpython2.7
CServerAssist.cpp:75: error: undefined reference to 'Py_Initialize'
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
<br/>LOCA