【问题标题】:Why am I getting this error when building the python module? [duplicate]为什么在构建 python 模块时出现此错误? [复制]
【发布时间】:2016-02-22 05:48:12
【问题描述】:

我目前正在用 C 语言构建一个 python 模块。我遵循了一个教程系列来让自己达到一个构建点,并且我对正在发生的事情有很好的了解。

但是,当我运行脚本来设置所有内容时,我得到了以下打印输出。看起来错误来自 python-dev 中的一个头文件;但是,我想在这里联系以确保这不是我正在做的事情。我将包含错误代码,我可以根据要求提供其他文件。

sudo python setup.py build
running build
running build_ext
building 'lidar' extension
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include -I/usr/include/python2.7 -c lidar_module.c -o build/temp.linux-armv6l-2.7/lidar_module.o
lidar_module.c: In function ‘lidar_test’:
lidar_module.c:8:6: warning: unused variable ‘sts’ [-Wunused-variable]
  int sts = 0;
      ^
In file included from /usr/include/python2.7/Python.h:58:0,
                 from lidar_module.c:1:
lidar_module.c: At top level:
/usr/include/python2.7/pyport.h:802:39: error: expected ‘,’ or ‘;’ before ‘void’
 #               define PyMODINIT_FUNC void
                                       ^
lidar_module.c:24:1: note: in expansion of macro ‘PyMODINIT_FUNC’
 PyMODINIT_FUNC initlidar(){
 ^
lidar_module.c:3:18: warning: ‘lidarError’ defined but not used [-Wunused-variable]
 static PyObject *lidarError;
                  ^
lidar_module.c:19:20: warning: ‘lidar_methods’ defined but not used [-Wunused-variable]
 static PyMethodDef lidar_methods[] = {
                    ^
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

我查看了头文件并在错误区域附近发现了它。

#ifndef PyMODINIT_FUNC
#       if defined(__cplusplus)
#               fndef PyMODINIT_FUNC
#       if defined(__cplusplus)
#               define PyMODINIT_FUNC extern "C" void
#       else /* __cplusplus */
#               define PyMODINIT_FUNC void
#       endif /* __cplusplus */
#endif

【问题讨论】:

    标签: python c python-2.7


    【解决方案1】:

    我确实不得不搜索控制台输出的行号,但我确实在这里找到了解决方案: Build Python (2.7) module on GCC 4.8 fails

    【讨论】:

    • 不鼓励仅链接的答案。将其标记为重复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多