代码之家  ›  专栏  ›  技术社区  ›  Buggieboy

pygame找不到包含文件“sdl.h”

  •  3
  • Buggieboy  · 技术社区  · 17 年前

    我正在尝试在使用pygame的Windows上构建下载的python应用程序。我已经安装了python 2.5和pygame 1.7.1。我对python不太熟悉,但我只是在Windows控制台命令行中键入顶级.py文件的名称。(我使用的是Win XP Pro。)

    这就是我得到的信息。

    C:\python25\include\pygame\pygame.h(68):致命错误C1083:无法打开include 文件:“sdl.h”:没有此类文件或目录

    我认为pygame是在SDL之上构建的,不需要单独安装SDL。不过,我安装了SDL 1.2.13,并将SDL INCLUDE文件夹添加到我的%INCLUDE%环境变量中。还是没有运气。

    我注意到了 C:\python25\lib\站点包\pygame 包含多个sdl*.dll文件,但在python树中的任何位置都没有sdl.h头文件。当然,我可以将SDL头复制到 C:\python25\include\pygame 文件夹,但这是一个令人讨厌的想法。

    有人知道正确的设置方法吗?

    编辑: 应用程序是 "The Penguin Machine" pygame app .

    2 回复  |  直到 12 年前
        1
  •  3
  •   nosklo    17 年前

    我尝试编译,但在我的Linux设备上出现了相同的错误:

    $ python setup.py build
    DBG> include = ['/usr/include', '/usr/include/python2.6', '/usr/include/SDL']
    running build
    running build_ext
    building 'surfutils' extension
    creating build
    creating build/temp.linux-i686-2.6
    creating build/temp.linux-i686-2.6/src
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/usr/include/python2.6 -I/usr/include/SDL -I/usr/include/python2.6 -c src/surfutils.c -o build/temp.linux-i686-2.6/src/surfutils.o
    In file included from src/surfutils.c:1:
    /usr/include/python2.6/pygame/pygame.h:68:17: error: SDL.h: Arquivo ou diretório inexistente
    In file included from src/surfutils.c:1:
    /usr/include/python2.6/pygame/pygame.h:312: error: expected specifier-qualifier-list before ‘SDL_VideoInfo’
    /usr/include/python2.6/pygame/pygame.h:350: error: expected specifier-qualifier-list before ‘SDL_Surface’
    src/surfutils.c:5: error: expected ‘)’ before ‘*’ token
    src/surfutils.c: In function ‘PyCollisionPoint’:
    src/surfutils.c:74: error: ‘SDL_Surface’ undeclared (first use in this function)
    src/surfutils.c:74: error: (Each undeclared identifier is reported only once
    src/surfutils.c:74: error: for each function it appears in.)
    src/surfutils.c:74: error: ‘surf1’ undeclared (first use in this function)
    src/surfutils.c:74: error: ‘surf2’ undeclared (first use in this function)
    src/surfutils.c:74: warning: left-hand operand of comma expression has no effect
    src/surfutils.c:92: error: ‘PySurfaceObject’ has no member named ‘surf’
    src/surfutils.c:97: error: ‘SDL_SRCALPHA’ undeclared (first use in this function)
    src/surfutils.c:111: error: ‘PySurfaceObject’ has no member named ‘surf’
    src/surfutils.c:161: warning: implicit declaration of function ‘collisionPoint’
    error: command 'gcc' failed with exit status 1
    

    似乎它试图编译一个名为 surfutils 需要SDL开发标题。

    所以我安装了 libsdl1.2-dev 使用我的分发包管理器打包,它工作得很好。您必须安装SDL开发头才能为您的系统构建它。

    所以你的问题是: 如何在Windows上安装SDL开发头文件,以及如何使程序使用它们?

    嗯,我可以回答第二个问题。必须编辑setup.py:

    #!/usr/bin/env python2.3
    
    from distutils.core       import setup, Extension
    from distutils.sysconfig  import get_config_vars
    
    includes = []
    includes.extend(get_config_vars('INCLUDEDIR'))
    includes.extend(get_config_vars('INCLUDEPY'))
    includes.append('/usr/include/SDL')
    
    print 'DBG> include =', includes
    
    setup(name='surfutils',
          version='1.0',
          ext_modules=[Extension(
                        'surfutils', 
                        ['src/surfutils.c'], 
                        include_dirs=includes,
                      )],
         )
    

    更改第9行。它说:

    includes.append('/usr/include/SDL')
    

    将此路径更改为SDL头所在的位置,即:

    includes.append(r'C:\mydevelopmentheaders\SDL')
    

    给游戏开发者留个便条,告诉他们你遇到了麻烦。它可以提供在您的平台上查找SDL头的更好方法。

        2
  •  1
  •   hlovdal    17 年前

    当您编译某些东西时,编译器会在几个目录中查找头文件,一些是硬编码和内置的,通常还有一些是作为编译器的参数提供的(例如“gcc-i/usr/local/include…”)。一个猜测是你错过了这个。如果不检查其他可能的原因 your error message .

    你需要 SDL 安装了开发库,但既然您说“我可以复制SDL头”,听起来您已经安装了。那么您的问题只是让编译器查找包含这些文件的include目录。