I am working on a chip8 emulator and when implementing the graphics, I am getting an error that states SDL2/SDL.h file not found
using an m1 mac vscode, I have the SDL2.framework folder in Library/Frameworks, and the makefile is as follows
CXX := g++
CXXFLAGS := -std=c++14 -Wall -I/Library/Frameworks/SDL2.framework/Headers
LDFLAGS := -F/Library/Frameworks -framework SDL2
TARGET := chip8_emulator
SRCS := chip8.cpp graphics.cpp
OBJS := $(SRCS:.cpp=.o)
$(TARGET): $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $^
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $<
clean:
rm -f $(TARGET) $(OBJS)
here is the graphics.hpp file for reference
#include <cstdint>
#include <SDL2/SDL.h>
class graphics
{
private:
int screen_width;
int screen_height;
int chip8_width;
int chip8_height;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
public:
graphics(int, int);
bool init_Screen();
void clear_screen();
void update_screen(uint32_t *);
void destroy_screen();
};
as you may guess, any function requiring the SDL library is throwing an undefined error
Most common solutions state that the -F flag in the makefile should resolve the issue, as I believe it is how the folders are structured on macs, there is no SDL2 folder. If i remove SDL2 and just #include<SDL.h>, i am getting the same error as well.
When you install
sdl2it also installssdl2-config.You can run this to get the extra flags you need:
Add the following to your Makefile: