skipping incompatible XX.so , undefined reference to `Py_Initialize'
我的系统是32位的ubuntu.
很奇怪我单独用命令行编译,却可以成功。但是,用ndk去编译,却提示错误。
#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/>LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
MY_CPP_LIST := $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
LOCAL_SRC_FILES += $(MY_CPP_LIST:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(SYSROOT)/usr/include/python2.7
LOCAL_LDLIBS:= -L$(SYSROOT)/usr/lib -lpython2.7
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
Build of configuration Default for project CenterCity **
bash /home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android/build_native.sh
NDK_ROOT = /usr/local/development/android-ndk-r9b
COCOS2DX_ROOT = /home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android/../../..
APP_ROOT = /home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android/..
APP_ANDROID_ROOT = /home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android
Using prebuilt externals
Android NDK: WARNING:jni/Android.mk:cocos2dcpp_shared: non-system libraries in linker flags: -lpython2.7
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:/home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android/../../../cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
make: Entering directory `/home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android'
[armeabi] Compile++ thumb: cocos2dcpp_shared <= main.cpp
...
[armeabi] SharedLibrary : libcocos2dcpp.so
/usr/local/development/android-ndk-r9b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /usr/lib/libpython2.7.so while searching for python2.7
make: Leaving directory `/home/yue/workspace/cocos2d-x-2.1.5/projects/CenterCity/proj.android'
/usr/local/development/android-ndk-r9b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpython2.7
CServerAssist.cpp:75: error: undefined reference to 'Py_Initialize'
CServerAssist.cpp:91: error: undefined reference to 'PyImport_ImportModule'
CServerAssist.cpp:92: error: undefined reference to 'PyObject_GetAttrString'
CServerAssist.cpp:94: error: undefined reference to 'PyTuple_New'
CServerAssist.cpp:105: error: undefined reference to 'Py_BuildValue'
CServerAssist.cpp:105: error: undefined reference to 'PyTuple_SetItem'
CServerAssist.cpp:109: error: undefined reference to 'PyEval_CallObjectWithKeywords'
CServerAssist.cpp:111: error: undefined reference to 'Py_Finalize'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1
**** Build Finished ****