【发布时间】:2016-11-19 04:03:45
【问题描述】:
我已经尝试了几个小时,但似乎无法做到。我已经下载了扩展程序并寻求帮助,但此时一切都让我感到困惑。 我想在我的项目中包含 SFML 库,我正在尝试使用 Visual Studio Code 编辑器,但由于某种原因它不符合要求。
它目前的样子的图片。 http://imgur.com/qJPlJua
我昨天也尝试了几个小时,但它就是不想工作。
【问题讨论】:
我已经尝试了几个小时,但似乎无法做到。我已经下载了扩展程序并寻求帮助,但此时一切都让我感到困惑。 我想在我的项目中包含 SFML 库,我正在尝试使用 Visual Studio Code 编辑器,但由于某种原因它不符合要求。
它目前的样子的图片。 http://imgur.com/qJPlJua
我昨天也尝试了几个小时,但它就是不想工作。
【问题讨论】:
我知道这个话题已经有几年的历史了,但是由于我正在寻找一种在 vs 代码中链接 sfml 库的方法并且我第一次来到这里,我想我会分享我找到的这个 git repo,它工作得很好到目前为止对我来说很好:
https://github.com/andrew-r-king/sfml-vscode-boilerplate
虽然我没有使用 SFML 2.5.1,所以我不得不在 c_cpp_properties.json 文件中进行一些小改动(我在 Ubuntu 18.04 上并通过包管理器安装了 sfml)
这里是我的 c_cpp_properties.json 文件:
{
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceFolder}/src",
"/usr/local/include/**",
"/usr/include/**"
],
"defines": [],
"cStandard": "c11",
"cppStandard": "c++17",
"forcedInclude": [
"${workspaceFolder}/src/PCH.hpp"
]
}
],
"version": 4
}
【讨论】:
我知道这个问题大约有两年了,但是在摆弄自己的任务来解决这个问题之后,我想出了一些东西。这不应该是最好的方法,但这对将来找到此答案的任何人都有好处。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"type": "shell",
"group": "build",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileBasenameNoExtension}.exe",
"-IC:\\SFML-2.5.1\\include",
"-LC:\\SFML-2.5.1\\lib",
"-lsfml-graphics",
"-lsfml-window",
"-lsfml-system",
],
"problemMatcher": [
"$gcc"
]
}
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
//"showReuseMessage": true
}
}
这应该与上述答案相同。按 CTRL+SHIFT+B 调出任务提示,或在命令面板中查找 Run task (CTRL+SHIFT+P)。请记住在项目的根目录中使用每个库的 .dll。
希望这会有所帮助。
【讨论】:
我搜索并找到了解决方案。
在tasks.json文件中,定义两个任务:
"tasks": [
{
"taskName": "Compilation",
"isBuildCommand": true,
"args": ["-c", "${workspaceRoot}\\main.cpp", "-IC:\\SFML-2.4.0\\include"]
},
{
"taskName": "Liaison du fichier compilé aux bibliothèques SFML",
"args": ["${workspaceRoot}\\main.o", "-o", "sfml-app.exe", "-LC:\\SFML-2.4.0\\lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system"]
}
],
并添加"suppressTaskName": true,
就像在 Linux 上一样。
您使用 CTRL + SHIFT + B 进行编译。要创建 .exe 文件:CTRL+SHIFT+P --> 然后“运行任务”,然后单击“Liaison du fichier compilé aux bibliothèques SFML”任务。
整个文件如下(对我来说):
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "Compilation",
"isBuildCommand": true,
"args": ["-c", "${workspaceRoot}\\main.cpp", "-IC:\\SFML-2.4.0\\include"]
},
{
"taskName": "Liaison du fichier compilé aux bibliothèques SFML",
"args": ["${workspaceRoot}\\main.o", "-o", "sfml-app.exe", "-LC:\\SFML-2.4.0\\lib", "-lsfml-graphics", "-lsfml-window", "-lsfml-system"]
}
],
"showOutput": "always"
}
【讨论】:
没什么好说的,除了官方网站上写的: https://code.visualstudio.com/docs/cpp/config-linux
我唯一需要做的就是为编译器添加额外的库链接,这可以在 tasks.json 部分完成:
...
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lsfml-graphics",
"-lsfml-system",
"-lsfml-window"
],
...
【讨论】: