c++ - 未找到 SDL2 begin_code.h 文件

标签 c++ clang sdl-2 coc.nvim

我最近才开始探索 SDL 2 并下载了 libstl2-dev在 Linux 上(如果重要的话,我正在使用 Mint)。

但是,当我包含标题时 #include <SDL2/SDL.h> , vim 一直报错 In included file: 'begin_code.h' file not [clang: pp_file_not_found] ,请注意,我正在将 coc 与 vim 一起使用。

我已经做了一些研究,但无法解决问题。特别是,我注意到 this post ,但问题是关于 VS 代码的,我不确定如何将其应用于 vim。

下面是我的部分代码。

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

void Board::help_init();

最佳答案

大多数 Linux 发行版 SDL 开发包应该包括可用的 pkg-config允许您查询可以传递给编译器的包含和库位置/名称的工具:

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

(或者你可以用 use $() for subcommand capture 代替反引号)

在这个 Debian 机器上 pkg-config返回这些路径/标志:

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

$ pkg-config --libs sdl2
-lSDL2

请注意 -I路径意味着你应该 #include <SDL.h> & friend ,不是#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>

尽管出于某种原因,SDL 附加库(如 SDL-image)的 Debian 包装已将 pkg-config 包名称大写:

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

关于c++ - 未找到 SDL2 begin_code.h 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71246274/

相关文章:

c++ - SDL 2.0 - 渲染 : PNG file doesn't render

fonts - 如何使用 SDL2 高效渲染字体和文本?

c++ - 如何像pygame一样限制sdl2 fps

c++ - 用自己的类序列化 QHash?

C++11:未触发 move 构造函数

c++ - 我在 Clang 中发现错误了吗?

android studio 3.2初始构建错误(找不到testCCompiler.c文件,windows 10)

c++ - 长度为零的数组

c++ - 何时 ¦ 不等于 ¦?

c - C 中奇怪的内存损坏