Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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\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;
}

The error I get is:

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.

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

like image 452
ILikeTurtles Avatar asked Nov 29 '13 02:11

ILikeTurtles


People also ask

Where are C++ libraries stored Mac?

On Mac and iOS the C Standard Library implementation is part of libSystem, a core library located in /usr/lib/libSystem.


2 Answers

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

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

I used home brew:

brew install sdl2

which puts the libraries in /usr/local/Cellar/

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

-L/usr/local/lib -lSDL2

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

like image 81
Grady Player Avatar answered Sep 27 '22 23:09

Grady Player


Your header files is under the Headers folder, so in order to include this properly:

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

But I recommend Installing with homebrew:

brew install sdl2

Homebrew will install SDL2 libSDL2.a file under /usr/local/lib and /usr/local/include, so you will just need to include this Library path using the -L for library and -I flag to add search in /usr/local/include dir:

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

And include:

#include <SDL2/SDL.h>
like image 31
Renato Prado Avatar answered Sep 27 '22 21:09

Renato Prado