Harry Zhou
Harry Zhou

Reputation: 83

SDL2 begin_code.h file not found

I just started exploring with SDL 2 recently and downloaded libstl2-dev on Linux (I'm using Mint, if that matters).

However, when I include the header #include <SDL2/SDL.h>, vim keeps telling me an error In included file: 'begin_code.h' file not [clang: pp_file_not_found], note that I'm using coc with vim.

I've done some research but I couldn't fix the problem. In particular, I noticed this post, but the question was on VS code and I'm not sure how to apply this to vim.

Below is a part of my code.

#include "board.h"
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>

void Board::help_init();

Upvotes: 4

Views: 1155

Answers (1)

genpfault
genpfault

Reputation: 52157

Most Linux distros SDL development packages should include usable pkg-config tooling that will allow you to query include and library locations/names that you can pass to the compiler:

g++ main.cpp `pkg-config --cflags --libs sdl2`

(Or you can use $() for subcommand capture instead of backticks)

On this Debian box pkg-config returns these paths/flags:

$ pkg-config --cflags sdl2
-D_REENTRANT -I/usr/include/SDL2

$ pkg-config --libs sdl2
-lSDL2

Note that -I path means you should #include <SDL.h> & friends, not #include <SDL2/SDL.h>:

// wrong
//#include <SDL2/SDL.h>
//#include <SDL2/SDL_image.h>
//#include <SDL2/SDL_timer.h>
// right
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_timer.h>

Though for whatever reason the Debian packaging for SDL add-on libraries like SDL-image have capitalized pkg-config package names:

g++ main.cpp `pkg-config --cflags --libs sdl2 SDL2_image`

Upvotes: 2

Related Questions