Linux '"SDL.h" 没有找到这样的文件或目录' 编译时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10488775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:12:57  来源:igfitidea点击:

'"SDL.h" no such file or directory found' when compiling

c++linuxsdl

提问by argoneus

Here's a piece of my current Makefile:

这是我当前的 Makefile 的一部分:

CFLAGS = -O2 -Wall -pedantic -std=gnu++11 `sdl-config --cflags --libs` -lSDL_mixer

I have libsdl installed properly, SDL.h is in /usr/include/sdl where it belongs, but it just won't compile. I also have the line #include "SDL.h"in my .h files, but still no go.

我已经正确安装了 libsdl,SDL.h 在它所属的 /usr/include/sdl 中,但它无法编译。#include "SDL.h"我的 .h 文件中也有该行,但仍然没有通过。

Anyone knows why?

有谁知道为什么?

采纳答案by larsks

If the header file is /usr/include/sdl/SDL.hand your code has:

如果头文件是/usr/include/sdl/SDL.h并且您的代码具有:

#include "SDL.h"

You need to either fix your code:

您需要修复您的代码:

#include "sdl/SDL.h"

Or tell the preprocessor where to find include files:

或者告诉预处理器在哪里可以找到包含文件:

CFLAGS = ... -I/usr/include/sdl ...

回答by bardes

Most times SDL is in /usr/include/SDL. If so then your #include <SDL.h>directive is wrong, it should be #include <SDL/SDL.h>.

大多数情况下,SDL 在/usr/include/SDL. 如果是这样,那么您的#include <SDL.h>指令是错误的,应该是#include <SDL/SDL.h>.

An alternative for that is adding the /usr/include/SDLdirectory to your include directories. To do that you should add -I/usr/include/SDLto the compiler flags...

另一种方法是将/usr/include/SDL目录添加到包含目录中。为此,您应该添加-I/usr/include/SDL到编译器标志...

If you are using an IDE this should be quite easy too...

如果您使用的是 IDE,这也应该很容易...

回答by Scott Stensland

The header file lives at

头文件位于

/usr/include/SDL/SDL.h

in your c++ code pull in this header using

在您的 C++ 代码中,使用

#include <SDL.h>

you have the correct usage of

你有正确的用法

sdl-config --cflags --libs

which will give you

这会给你

-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
-L/usr/lib/x86_64-linux-gnu -lSDL

at time you may also see this usage which works for a standard install

有时您可能还会看到此用法适用于标准安装

pkg-config --cflags --libs sdl

which supplies you with

它为您提供

-D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL -lSDL

回答by StackAttack

For Simple Direct Media Layer 2(SDL2), after installing it on Ubuntu 16.04 via:

对于简单直接媒体层 2(SDL2),在 Ubuntu 16.04 上通过以下方式安装后:

sudo apt-get install libsdl2-dev

I used the header:

我使用了标题:

#include <SDL2/SDL.h>  

and the compiler linker command:

和编译器链接器命令:

-lSDL2main -lSDL2 

Additionally, you may also want to install:

此外,您可能还想安装:

apt-get install libsdl2-image-dev  
apt-get install libsdl2-mixer-dev  
apt-get install libsdl2-ttf-dev  

With these headers:

使用这些标题:

#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>  

and the compiler linker commands:

和编译器链接器命令:

-lSDL2_image 
-lSDL2_ttf 
-lSDL2_mixer

回答by Qohelet

Having a similar case and I couldn't use StackAttacks solution as he's referring to SDL2 which is for the legacy code I'm using too new.

有一个类似的情况,我不能使用StackAttack的解决方案,因为他指的是 SDL2,它用于我使用的太新的遗留代码。

Fortunately our friends from askUbuntuhad something similar:

幸运的是,我们来自askUbuntu的朋友有类似的东西:

Download SDL

下载 SDL

tar xvf SDL-1.2.tar.gz
cd SDL-1.2
./configure
make
sudo make install

回答by Mayank Sharma

the simplest idea is to add pkg-config --cflags --libs sdl2 while compiling the code.

最简单的想法是在编译代码时添加 pkg-config --cflags --libs sdl2 。

g++ file.cpp `pkg-config --cflags --libs sdl2`

g++ file.cpp `pkg-config --cflags --libs sdl2`