vscode中的sdl.h没有这样的文件或目录
I'm trying to add the relevant "-I"path_to_your_SDL_include_directory""
as outlined in several similar posts such as
我的文件结构如下。我的main.cpp在myproject/src
中。我已经复制了SDL的所有内容。 sdl2.dll
生活在myproject/lib/sdl2_lib
中。
以下是视觉摘要以及我的代码。
main.cpp
#include <iostream>
#include <SDL.h>
const int WIDTH = 800, HEIGHT = 600;
int main( int argc, char *argv[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Window *window = SDL_CreateWindow( "Hello SDL WORLD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI );
if ( NULL == window )
{
std::cout << "Could not create window: " << SDL_GetError( ) << std::endl;
return 1;
}
SDL_Event windowEvent;
while ( true )
{
if ( SDL_PollEvent( &windowEvent ) )
{
if ( SDL_QUIT == windowEvent.type )
{ break; }
}
}
SDL_DestroyWindow( window );
SDL_Quit( );
return EXIT_SUCCESS;
}
makefile
all:
g++ -I lib/SDL2_lib/include -Llib/SDL2_lib/lib -o Main src/main.cpp
任务
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I lib/SDL2_lib/include",
"-L lib/SDL2_lib/lib",
"-lmingw32",
"-lSDL2main",
"-lSDL2",
"-o",
"${workspaceFolder}/bin\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
。
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/lib/SDL2_lib/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\g++.exe",
"cStandard": "gnu11",
"cppStandard": "c++14",
"intelliSenseMode": "windows-gcc-x86",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
"-I lib/SDL2_lib/include",
"-L lib/SDL2_lib/lib",
"-lmingw32",
"-lSDL2main",
"-lSDL2"
]
}
],
"version": 4
}
png“ rel =” nofollow noreferrer“>
编辑:我还应该添加一个添加一个随机文件名而不是sdl.h
强调整个Include语句,而不仅仅是结束。很明显,VSCODE确实知道它存在,它只是不会将其添加到程序中,这就是我猜测
Edit2:运行Make
从PowerShell发出以下错误:
I'm trying to add the relevant "-I"path_to_your_SDL_include_directory""
as outlined in several similar posts such as this one. I have tried three approaches;, adding it to tasks.json, Makefile and c_cpp_properties.json.
My file structure is as follows. My main.cpp is in MyProject/src
. I have copied all the contents of SDL's include folder to MyProject/lib/SDL2_lib/include
and copied the lib folder to MyProject/lib/SDL2_lib/lib
. SDL2.dll
lives in MyProject/lib/SDL2_lib
.
The following is a visual summary as well as my code.
main.cpp
#include <iostream>
#include <SDL.h>
const int WIDTH = 800, HEIGHT = 600;
int main( int argc, char *argv[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Window *window = SDL_CreateWindow( "Hello SDL WORLD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI );
if ( NULL == window )
{
std::cout << "Could not create window: " << SDL_GetError( ) << std::endl;
return 1;
}
SDL_Event windowEvent;
while ( true )
{
if ( SDL_PollEvent( &windowEvent ) )
{
if ( SDL_QUIT == windowEvent.type )
{ break; }
}
}
SDL_DestroyWindow( window );
SDL_Quit( );
return EXIT_SUCCESS;
}
Makefile
all:
g++ -I lib/SDL2_lib/include -Llib/SDL2_lib/lib -o Main src/main.cpp
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I lib/SDL2_lib/include",
"-L lib/SDL2_lib/lib",
"-lmingw32",
"-lSDL2main",
"-lSDL2",
"-o",
"${workspaceFolder}/bin\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/lib/SDL2_lib/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\g++.exe",
"cStandard": "gnu11",
"cppStandard": "c++14",
"intelliSenseMode": "windows-gcc-x86",
"configurationProvider": "ms-vscode.makefile-tools",
"compilerArgs": [
"-I lib/SDL2_lib/include",
"-L lib/SDL2_lib/lib",
"-lmingw32",
"-lSDL2main",
"-lSDL2"
]
}
],
"version": 4
}
Despite all this, I am getting the error:
Edit: I should also add that adding a random file name instead of SDL.h
underlines the entire include statement instead of just the end. So clearly, VSCode does know it exists, its just not adding it to the program which is what I'm guessing
Edit2: Running make
from powershell gives the following error:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显然,您有两个问题。
,让我们首先解决makefile的内容:
您的makefile中有一个错字,它说
sdl2_lib/code
而不是<< 代码> sdl2_lib/lib 。修复此操作后,您必须添加库以链接。从技术上讲,您只需要
libsdl2.la
(假设动态链接),因为您已经编写了自己的main()
函数(因此您不需要sdl2main
代码
> 请提供编译器输出(作为文本,而不是图像),但请勿在尝试此操作之前:
选项:指定整个库的文件名:
选项二:静态(您不需要DLL)
关于VSCODE:
我不认为有您的配置有任何错误。
It is clear that you have two problems.
Let's address the Makefile thing first:
There's a typo in your Makefile, it says
SDL2_lib/libr
instead ofSDL2_lib/lib
.After fixing that, you must add the libraries to link with. Technically, you only need
libSDL2.la
(assuming dynamic linking) since you already wrote your ownmain()
function (therefore you don't needSDL2main
.So, the command line in your Makefile should look like this (note how I put the project's files before the libs to guarantee symbols are loaded correctly, this becomes more important when using intermediate files):
If that doesn't work, please provide the compiler output (as text, not image) but not before trying this:
Option one: Specify the whole library's filename:
Option two: Link statically (you won't need the DLL)
About VSCode:
I don't think there's anything wrong with your configuration. You may want to try switching to backslashes (which should't make a difference anyway) or (yes, for real) reloading VSCode.
我没有使用Windows和Vscode,但我想您可以尝试
或
I haven't used Windows and VSCode but I guess you can try
or
标志之间不应该有空间
IE
“ -i lib/sdl2_lib/include”应该是“ -ilib/sdl2_lib/include”
“ -l lib/sdl2_lib/lib”应为“ -llib/sdl2_lib/lib”
There shouldn't be space between flags
ie
"-I lib/SDL2_lib/include" should be "-Ilib/SDL2_lib/include"
"-L lib/SDL2_lib/lib" should be "-Llib/SDL2_lib/lib"
MACOS
安装工具和LIB
创建项目结构
我的
makefile
我的
vscode
配置.vscode/settings.json
file> file> code> .vscode/c_cpp_properties。 json 文件
.vscode/laining.json
文件.vscode/tasks.json
文件MacOS
Install the tools and libs
Create project structure
My
Makefile
my
vscode
configuration.vscode/settings.json
file.vscode/c_cpp_properties.json
file.vscode/launch.json
file.vscode/tasks.json
file