我正在尝试使用SDL。我有一个/Library/Frameworks
名为的文件夹SDL2.framework
。我想将文件包含SDL.h
在我的项目中。我该怎么做呢?我的代码如下所示:
// Example program:
// Using SDL2 to create an application window
#include <SDL.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
SDL_Window *window; // Declare a pointer
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
// Check that the window was successfully made
if (window == NULL) {
// In the event that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
// The window is open: enter program loop (see SDL_PollEvent)
SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();
return 0;
}
我得到的错误是:
Aarons-MacBook-Air:SDL aaron$ g++ main.cpp
main.cpp:4:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
^ 1 error generated.
如何正确包含SDL文件?这里面SDL2.framework
,headers
,SDL.h
...
您显然需要为此制作一个构建脚本,但是重要的部分是:
-I/usr/local/include
或您的标头安装在任何地方。
我用家庭酿造的:
brew install sdl2
把图书馆放进去 /usr/local/Cellar/
因此,如果您需要指定lib路径,则还将添加:
-L/usr/local/lib -lSDL2
我也将您的包含行更改为 #include <SDL2/SDL.h>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句