【问题标题】:Cythonizing fails because of unknown type name 'uint64_t'由于未知类型名称“uint64_t”,Cythonizing 失败
【发布时间】:2018-05-18 00:56:29
【问题描述】:

这可能是一个新手问题。当完全相同的代码在 linux 上运行时,我无法对简单的 helloworld.pyx 教程脚本进行 cythonize:

print("hello world")

这里是 setup.py 脚本:

from distutils.core import setup

from Cython.Build import cythonize

setup(ext_modules = cythonize('helloworld.pyx'))

但我在运行 python setup.py build_ext --inplace 后得到了这个:

running build_ext
building 'helloworld' extension
creating build
creating build/temp.macosx-10.7-x86_64-3.6
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/haotian/anaconda3/include -arch x86_64 -I/Users/haotian/anaconda3/include -arch x86_64 -I/Users/haotian/anaconda3/include/python3.6m -c helloworld.c -o build/temp.macosx-10.7-x86_64-3.6/helloworld.o
In file included from helloworld.c:16:
In file included from /Users/haotian/anaconda3/include/python3.6m/Python.h:34:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
/usr/include/sys/resource.h:196:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];
        ^
/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
        uint64_t ri_phys_footprint;
        ^
/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_start_abstime;
        ^
/usr/include/sys/resource.h:206:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_exit_abstime;
        ^
/usr/include/sys/resource.h:210:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];
        ^
/usr/include/sys/resource.h:211:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:212:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:213:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:214:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:215:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:216:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:217:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
error: command 'gcc' failed with exit status 1

我使用的是 MacOS 10.13.1、python 3.6.3、Cython 0.27.3 和 clang-900.0.38。

显然包含 stdint.h 存在问题,我应该如何在 Cython 中进行呢?

编辑: 我的 gcc 在 /usr/bin/gcc

gcc --version

显示:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

【问题讨论】:

  • 你确定你使用的是clang而不是gcc吗?你的gcc是哪个版本的,如果日志可信的话用哪个?
  • helloworld.c 可能不包含#include <stdint.h>。或者,你被困在“垃圾模式”,又名 gnu90。将-std=c99-std=c11 传递给gcc 编译器。
  • 我修改了版本号@ead
  • 看起来clang“假装”是gcc并使用相当老的gcc-headers(4.2.1)。您应该直接使用 clang(将 CC 环境变量设置为 clang)或安装更新的 gcc 版本
  • 设置 CC 似乎不起作用,我尝试手动运行 gcc-7:/usr/local/bin/gcc-7 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/haotian/anaconda3/include -arch x86_64 -I/Users/haotian/anaconda3/include -arch x86_64 -I/Users/haotian/anaconda3/include/python3.6m -c helloworld.c -o build/temp.macosx-10.7-x86_64-3.6/helloworld.o 这也给了我同样的错误

标签: python c cython


【解决方案1】:

在迁移到新 Mac 后,我遇到了类似的情况。只是重新安装 brew 并没有解决问题。我必须删除 /usr/local/include 才能解决此问题。

(Comment from Cython Issue on Github)

【讨论】:

  • 这也是我修复的必要条件。谢谢!
【解决方案2】:

我找到了解决问题的方法。

似乎在安装 High Sierra 之后,/usr/local/include 中的一些头文件搞砸了,导致 brew 安装出现故障。卸载并重新安装 brew 解决了这个问题。

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2014-11-19
    • 2018-10-27
    相关资源
    最近更新 更多