当前位置: 技术问答>linux和unix
skipping incompatible XX.so , undefined reference to `Py_Initialize'
来源: 互联网 发布时间:2017-05-08
本文导语: 我的系统是32位的ubuntu. 很奇怪我单独用命令行编译,却可以成功。但是,用ndk去编译,却提示错误。 #include CServerAssist::CServerAssist(void) { } CServerAssist::~CServerAssist(void) { } ... ... CServerAssist::EmLoginCode CServerAssist::Exe...
我的系统是32位的ubuntu.
很奇怪我单独用命令行编译,却可以成功。但是,用ndk去编译,却提示错误。
编译成功的命令行
ndk编译失败提示信息
=========================== makefile文件:
======================================= ndk编译失败全部提示
很奇怪我单独用命令行编译,却可以成功。但是,用ndk去编译,却提示错误。
#include
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(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
ndk编译失败提示信息
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'
=========================== makefile文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
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)
======================================= ndk编译失败全部提示
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