问题描述
我正在编写一个make文件来编译一个非常简单的SDL2程序。
到目前为止,它编译SDL2很好,现在我正在编译扩展框架SDL2_image和SDL_ttf。
看来,MAKE正确地找到了SDL_ttf.h,但是后来SDL_ttf.h找不到SDL2 / SDL.h。
以下是错误:
cpp:3:
/Library/Frameworks/SDL2_ttf.framework/Headers/SDL_ttf.h:30:10:致命错误:
'SDL2 / SDL.h'文件未找到
#include < SDL2 / SDL.h>
^
生成了1个错误。
make:*** [main.o]错误1
SDL2像这样:
#include< SDL2 / SDL.h>
我甚至无法编译一个基本程序(SDL2没有扩展名)。我将其改为:
#includeSDL.h
(我也听说后一种语法对于可移植性更正确。)
任何想法?
我在OS X Mavericks上这样做
这里是我的文件:
main.cpp#include< iostream>
#includeSDL.h
#includeSDL_ttf.h
#includeSDL_image.h
int main(int argc,char * arg [])
{
if(SDL_Init(SDL_INIT_EVERYTHING)!= 0)
{
std :: cout< ERROR<< std :: endl;
return -1;
}
SDL_Window * window = SDL_CreateWindow(Name,SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640,
480,
SDL_WINDOW_OPENGL);
if(TTF_Init()== -1)
{
sdl :: cout< SDL_ttf failed< std :: endl;
}
SDL_Surface * tempSurface = IMG_Load(test.png);
if(tempSurface == nullptr)
{
std :: cout< failed to load test.png<< std :: endl;
}
SDL_FreeSurface(tempSurface);
SDL_Delay(5999);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
makefile
CXX = clang ++
SDL = -framework SDL2 -framework SDL2_ttf -framework SDL2_image
CXXFLAGS = -Wall -c -std = c ++ 11 -I /Library/Frameworks/SDL2.framework/Headers -I /Library/Frameworks/SDL2_ttf.framework/Headers -I /Library/Frameworks/SDL2_image.framework/Header
LDFLAGS = $(SDL)-F / Library / Frameworks
EXE = test
all:$(EXE)
$(EXE):main .o
$(CXX)$(LDFLAGS)$& -o $ @
main.o:main.cpp
$(CXX)$(CXXFLAGS)$& -o $ @
clean:
rm * .o&& rm $(EXE)
编辑:
我已根据DMG文件中的说明将SDL2和SDL2_ttf安装到/ Library / Frameworks文件夹中。
解决方案通过DMG的SDL2库,这是正确的方式使它们可用于Xcode。
但是,我想使用g ++和编译通过MAKE导致的问题详细如上。
答案是安装SDL2和扩展库UNIX风格,详情如下:
使用include这样的语句:
#includeSDL.h
#includeSDL_ttf.h
#includeSDL_image.h
我的makefile现在看起来像这样(注意使用sdl2 -config和TTF和图像库如何链接):
CXX = clang ++
SDL =`sdl2-config - -libs`
CXXFLAGS = -Wall -c -std = c ++ 11`sdl2-config --cflags`
LDFLAGS = $(SDL)-lSDL2_ttf -lSDL2_image
EXE = test
all:$(EXE)
$(EXE):main.o
$(CXX)$(LDFLAGS) -o $ @
main.o:main.cpp
$(CXX)$(CXXFLAGS)$& -o $ @
I am writing a make file to compile a very simple SDL2 program.
So far it compiles SDL2 just fine, and now I am working on compiling the extension frameworks SDL2_image and SDL_ttf.
It seems that MAKE is finding the SDL_ttf.h properly, but then SDL_ttf.h cant find "SDL2/SDL.h".
Here is the error:
In file included from main.cpp:3: /Library/Frameworks/SDL2_ttf.framework/Headers/SDL_ttf.h:30:10: fatal error: 'SDL2/SDL.h' file not found #include <SDL2/SDL.h> ^ 1 error generated. make: *** [main.o] Error 1
Note, when I included SDL2 like this:
#include <SDL2/SDL.h>
I could not compile even a basic program (SDL2 with no extensions). I got it to work by changing it to this:
#include "SDL.h"
(I also heard the latter syntax is more correct for portability?)
Any ideas?
I am doing this on OS X Mavericks
Here are my files:main.cpp
#include <iostream> #include "SDL.h" #include "SDL_ttf.h" #include "SDL_image.h" int main(int argc, char * arg[]) { if(SDL_Init(SDL_INIT_EVERYTHING) != 0) { std::cout << "ERROR" <<std::endl; return -1; } SDL_Window * window = SDL_CreateWindow("Name", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL); if (TTF_Init() == -1) { sdl::cout << "SDL_ttf failed" << std::endl; } SDL_Surface* tempSurface = IMG_Load("test.png"); if (tempSurface == nullptr) { std::cout << "failed to load test.png" << std::endl; } SDL_FreeSurface(tempSurface); SDL_Delay(5999); SDL_DestroyWindow(window); SDL_Quit(); return 0;
}
makefile
CXX = clang++ SDL = -framework SDL2 -framework SDL2_ttf -framework SDL2_image CXXFLAGS = -Wall -c -std=c++11 -I /Library/Frameworks/SDL2.framework/Headers -I /Library/Frameworks/SDL2_ttf.framework/Headers -I /Library/Frameworks/SDL2_image.framework/Header LDFLAGS = $(SDL) -F /Library/Frameworks EXE = test all: $(EXE) $(EXE): main.o $(CXX) $(LDFLAGS) $< -o $@ main.o: main.cpp $(CXX) $(CXXFLAGS) $< -o $@ clean: rm *.o && rm $(EXE)
Edit:
I have SDL2 and SDL2_ttf installed into the /Library/Frameworks folder per the instructions in the DMG files.
解决方案I had installed the SDL2 libraries via DMG, which is the correct way to make them available to Xcode.
However, I want to use g++ and compile via MAKE which led to the problems I detailed above.
The answer is to install SDL2 and the extension libraries UNIX style as detailed herehttp://www.ginkgobitter.org/sdl/?FAQMacOSX
I was then able to use include statements like this:
#include "SDL.h" #include "SDL_ttf.h" #include "SDL_image.h"
My makefile now looks like this (note use of sdl2-config and how TTF and image libraries are linked):
CXX = clang++ SDL = `sdl2-config --libs` CXXFLAGS = -Wall -c -std=c++11 `sdl2-config --cflags` LDFLAGS = $(SDL) -lSDL2_ttf -lSDL2_image EXE = test all: $(EXE) $(EXE): main.o $(CXX) $(LDFLAGS) $< -o $@ main.o: main.cpp $(CXX) $(CXXFLAGS) $< -o $@
这篇关于SDL_ttf找不到“SDL.h”,但main.cpp可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!