本文介绍了你如何从 MAC 的/Library/Framework 文件夹中包含 C++ 中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use SDL. I have a folder in /Library/Frameworks called SDL2.framework. I want to include the file SDL.h in my project. How do I do this? My code looks like:

// 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
", 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...

How do I properly include the SDL file? It is inside SDL2.framework, headers, SDL.h...

推荐答案

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

you will want to make a build script for this obviously, but the important parts are:

-I/usr/local/include 或者你的头文件安装的任何地方.

-I/usr/local/include or wherever your headers get installed.

我用的是家酿:

brew install sdl2

将库放在 /usr/local/Cellar/

所以如果你需要指定lib路径,你还要添加:

so if you need to specify the lib path you will also add:

-L/usr/local/lib -lSDL2

我还将您的包含行更改为 #include

I also changed your include line to #include <SDL2/SDL.h>

这篇关于你如何从 MAC 的/Library/Framework 文件夹中包含 C++ 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 12:52
查看更多