我试图创建一个Cmake文件来编译旧的C ++项目,但是当我运行make命令时,我遇到了这个编译错误:
In file included from /home/leontes/Dropbox/Siadex_Planner_ROS/planner/src/pyAPI.cpp:23:0:
/usr/include/python2.7/structmember.h:40:5: error: ‘Py_ssize_t’ does not name a type
Py_ssize_t offset;
^
/usr/include/python2.7/structmember.h:88:24: error: expected constructor, destructor, or type conversion before ‘PyMember_Get’
PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
^
/usr/include/python2.7/structmember.h:89:17: error: expected constructor, destructor, or type conversion before ‘PyMember_Set’
PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
^
/usr/include/python2.7/structmember.h:92:24: error: expected constructor, destructor, or type conversion before ‘PyMember_GetOne’
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
^
/usr/include/python2.7/structmember.h:93:17: error: expected constructor, destructor, or type conversion before ‘PyMember_SetOne’
PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
^
make[2]: *** [CMakeFiles/planner.dir/src/pyAPI.cpp.o] Error 1
make[1]: *** [CMakeFiles/planner.dir/all] Error 2
make: *** [all] Error 2
这是Python的系统库...
我修复了旧版本的proyect包含的内容,它工作正常,但新版本没有。
我建立的Cmakelist.txt是这样的:
cmake_minimum_required(VERSION 2.8.3)
project(planner)
#Set headers directory
include_directories(include ${PYTHON_INCLUDE_PATH})
#Set source files
file(GLOB SOURCES "src/*.cpp")
#Set python vars
#Compiler flags
execute_process(COMMAND python-config --cflags OUTPUT_VARIABLE PYTHON_CPPFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
#Libraries
execute_process(COMMAND python-config --libs OUTPUT_VARIABLE PYTHON_EXTRA_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
#Linker flags
execute_process(COMMAND python-config --ldflags OUTPUT_VARIABLE PYTHON_LDFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
#Concatenate the new flags with the old ones
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${PYTHON_CPPFLAGS})
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${PYTHON_LDFLAGS})
#Define preprocessor directives for debugger.cpp
if(EXISTS /usr/include/readline.h)
add_definitions(-DHAVE_LIBREADLINE)
add_definitions(-DHAVE_READLINE_H)
endif(EXISTS /usr/include/readline.h)
if(EXISTS /usr/include/readline/readline.h)
add_definitions(-DHAVE_LIBREADLINE)
add_definitions(-DHAVE_READLINE_READLINE_H)
endif(EXISTS /usr/include/readline/readline.h)
if(EXISTS /usr/include/history.h)
add_definitions(-DHAVE_READLINE_HISTORY)
add_definitions(-DHAVE_HISTORY_H)
endif(EXISTS /usr/include/history.h)
if(EXISTS /usr/include/readline/history.h)
add_definitions(-DHAVE_READLINE_HISTORY)
add_definitions(-DHAVE_READLINE_HISTORY_H)
endif(EXISTS /usr/include/readline/history.h)
#Define preprocessor directives for stacknode.cpp
add_definitions(-DUSE_AC3)
#add_definitions(-DUSE_PC2)
#add_definitions(-DUSE_PC2_CL)
#Add a binary executable
add_executable(planner nodes/planner.cpp ${SOURCES})
#And link it
target_link_libraries(planner python2.7 readline ${PYTHON_EXTRA_LIBS})
我错过了什么?
编辑:
用于编译旧的' make'
g++ -DHAVE_CONFIG_H -I. -I../.. -Wall -Iheaders -I../xmlrpc/headers -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -DPYTHON_FOUND -DWITH_XMLRPC -g -O2 -DBUFFER_STACK -MT sources/pyAPI.o -MD -MP -MF $depbase.Tpo -c -o sources/pyAPI.o sources/pyAPI.cpp &&\
用于在新的' make'
中编译的命令/usr/bin/c++ -DHAVE_LIBREADLINE -DHAVE_READLINE_HISTORY -DHAVE_READLINE_HISTORY_H -DHAVE_READLINE_READLINE_H -DUSE_PC2_CL -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -I/home/leontes/Dropbox/Siadex_Planner_ROS/planner/include -I/usr/include/python2.7 -o CMakeFiles/planner.dir/src/pyAPI.cpp.o -c /home/leontes/Dropbox/Siadex_Planner_ROS/planner/src/pyAPI.cpp