繁体   English   中英

如何从MAC中的/ Library / Framework文件夹包含C ++文件

[英]How do you include files in C++ from the /Library/Framework folder in MAC

我正在尝试使用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.frameworkheadersSDL.h ...

您显然希望为此创建一个构建脚本,但是重要的部分是:

-I/usr/local/include或您的标头安装在任何地方。

我用家庭酿造的:

brew install sdl2

将库放在/usr/local/Cellar/

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

-L/usr/local/lib -lSDL2

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

您的头文件在Headers文件夹下,因此为了正确包含此文件:

clang++ -std=c++11 -stdlib=libc++ -I/Library/Frameworks/SDL2.framework/Headers/

但是我建议使用自制软件安装:

brew install sdl2

Homebrew将在/ usr / local / lib和/ usr / local / include下安装SDL2 libSDL2.a文件,因此您只需要使用-L for library和-I标志包括此Library路径,即可在/ usr /中添加搜索本地/包含目录:

clang++ -std=c++11 -stdlib=libc++ main.cpp -I/usr/local/include -L/usr/local/lib -lSDL2 -o programfile

包括:

#include <SDL2/SDL.h>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM