I have tried compiling a test code I found online:
#include <SDL2/SDL.h>
#include <iostream>
int main()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cout << "Failed to initialize the SDL2 libraryn";
return -1;
}
SDL_Window *window = SDL_CreateWindow("SDL2 Window",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
680, 480,
0);
if(!window)
{
std::cout << "Failed to create windown";
return -1;
}
SDL_Surface *window_surface = SDL_GetWindowSurface(window);
if(!window_surface)
{
std::cout << "Failed to get the surface from the windown";
return -1;
}
SDL_UpdateWindowSurface(window);
SDL_Delay(5000);
}
But it outputs:
main.cpp:1:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
^~~~~~~~~~~~
1 error generated.
The problem is: I have already installed SDL2, SDL2_image and SDL2_ttf through homebrew on my Mac.
From what I have read online, I shouldn’t have to link stuff in the command since I have those installed and that I should only use “-lSDL2”
I am a beginner in C++ and I really don’t understand how libraries work.
New contributor
odypdoydoyd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2