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

发布于 07-19 09:17 字数 762 浏览 3 评论 0原文

我正在尝试在 Windows 上构建一个使用 Pygame 的下载的 Python 应用程序。 我已经安装了Python 2.5和Pygame 1.7.1。 我是 Python 新手,但我只是尝试在 Windows 控制台命令行上输入顶级 .py 文件的名称。 (我使用的是 Win XP Pro。)

这是我收到的消息。

C:\Python25\include\pygame\pygame.h(68) : 致命错误 C1083: 无法打开包含 文件:'SDL.h':没有这样的文件或目录

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

我注意到 C:\Python25\Lib\site-packages\pygame 包含几个 SDL*.DLL 文件,但 python 树中的任何位置都没有 sdl.h 头文件。 当然,我可以将 sdl 头文件复制到 C:\Python25\include\pygame 文件夹中,但这是一个令人反感的想法。

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

编辑: 该应用程序是“The Penguin Machine”pygame 应用程序

I am trying to build a downloaded Python app on Windows that uses Pygame. I have installed Python 2.5 and Pygame 1.7.1. I am new to Python, but I just tried typing the name of the top level .py file on a Windows console command line. (I'm using Win XP Pro.)

This is the message that I get.

C:\Python25\include\pygame\pygame.h(68) : fatal error C1083: Cannot open include
file: 'SDL.h': No such file or directory

I thought that Pygame was built on top of SDL and that a separate SDL install was not necessary. Nevertheless, I installed SDL 1.2.13 and added the SDL include folder to my %INCLUDE% environment variable. Still no luck.

I noticed that C:\Python25\Lib\site-packages\pygame includes several SDL*.DLL files, but there is no sdl.h header file anywhere in the python tree. Of course, I could copy the sdl headers into the C:\Python25\include\pygame folder, but that is a distasteful idea.

Anybody know the right way to set things up?

EDIT:
The application is "The Penguin Machine" pygame app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

っ左2024-07-26 09:17:20

我尝试编译并在我的 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 标头的更好方法。

I tried compiling and got the same errors on my linux box:

$ 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

Seems like it tries to compile a extension called surfutils which needs SDL development headers.

So I installed the libsdl1.2-dev package using my distribution package manager and it worked just fine. You must install SDL development headers in order to build it for your system.

So your question really is: How do I install SDL development headers on windows, and how I make the program use them?

Well, I can answer the second question. You must edit 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,
                  )],
     )

Change line 9. It says:

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

Change this path to wherever your SDL headers are, i.e.:

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

Leave a note to the game developer to say you're having this trouble. It could provide a better way of finding SDL headers on your platform.

梦屿孤独相伴2024-07-26 09:17:20

当您编译某些内容时,编译器会在多个目录中查找头文件,其中一些是硬编码和内置的,通常有些是作为编译器的参数给出的(例如“gcc -I/usr/local/include ...”)。 一种猜测是你错过了这一点。 如果没有,请检查错误消息。

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

When you compile something the compiler looks up header files in several directories, some hardcoded and build in, and typically some given as arguments to the compiler (like for instance "gcc -I/usr/local/include ..."). One guess is that you are missing this. If not check out other possible causes to your error message.

You will need to have the SDL Development Libraries installed, but since you say "I could copy the sdl headers" it sounds like you already have. Then your problem is only to get the compiler to look in the include directory containing those files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文