当我尝试在mac上使用vscode和clang++创建一个窗口时,我遇到了一个问题,安装了sdl2(使用自制软件),但vscode找不到它。这是我在终端中得到的错误。
* Executing task: C/C++: clang build active file
Starting build...
/usr/bin/clang -std=gnu++14 -std=c++17 -stdlib=libc++ -g
/Users/jst_/Coding/VS.Code_C++/Main.CPP -o
/Users/jst_/Coding/VS.Code_C++/Main
/Users/jst_/Coding/VS.Code_C++/Main.CPP:1:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
^~~~~~~~~~~~
1 error generated.
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
* Terminal will be reused by tasks, press any key to close it.
The code for the window is
#include <SDL2/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("My Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
if (!window) {
// Handle window creation failure
SDL_Quit();
return 1;
}
SDL_Delay(3000); // Pause for 3 seconds
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
字符串
Tasks json是
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-I",
"/opt/homebrew/opt/sdl2", // Replace this path with the correct one
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"group": "build",
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
型
C_cpp_properties json是
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/opt/sdl2",
"/opt/homebrew/Cellar/sdl2/2.28.5/include"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
型
我尝试了多次,以找到不同的路径,我finnaly找到了正确的路径,但它没有什么区别,我仍然得到了同样的错误。
1条答案
按热度按时间bvn4nwqk1#
在使用clang编译的Tasks.json中的第一个任务中,您忘记将路径添加到args中,这就是为什么您会收到错误,因为您正在使用clang编译,并且在该任务中,包含路径(SDL/sdl2.h所在的位置)丢失。