mac 中c语言文件,如何在MAC中的/ Library / Framework文件夹中包含C中的文件

我正在尝试使用SDL.我在/ Library / Frameworks中有一个名为SDL2.framework的文件夹.我想在我的项目中包含文件SDL.h.我该怎么做呢?我的代码看起来像:

// Example program:

// Using SDL2 to create an application window

#include

#include

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

^ 1 error generated.

如何正确包含SDL文件?它位于SDL2.framework,headers,SDL.h …

解决方法:

你会想要为此制作一个构建脚本,但重要的部分是:

-I /usr/local/include或安装标头的位置.

我用家酿:

brew安装sdl2

将库放在/usr/local/Cellar /

因此,如果您需要指定lib路径,您还将添加:

-L /usr/local/lib -lSDL2

我还将您的包含行更改为#include< SDL2 / SDL.h>

标签:c,compilation,macos,include,sdl

来源: https://codeday.me/bug/20190930/1835939.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值