How do i link the SFML libraries in Visual Studio Code?

不问归期 提交于 2019-11-28 01:24:30

I searched and I have finded.

In the tasks.json file, define two tasks :

"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"]
    }
],

and add "suppressTaskName": true,

So it's like on Linux.

You compile with CTRL + SHIFT + B. For create the .exe file : CTRL+SHIFT+P --> then "run task" then click then click on the "Liaison du fichier compilé aux bibliothèques SFML" task.

the entire file is as (for me):

{
// 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"

}

Cordially.

I know this question is about two years old, but after fiddling with my own tasks to solve this problem, and came up with something. This shouldn't be the best way to do it, but this should be good for anyone that finds this answer in the future.


{
    // 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
    }
}

This should work the same as the above answer. Hit CTRL+SHIFT+B to bring up the Task prompt, or look up Run task in the Command Palette (CTRL+SHIFT+P). Remember to have the .dlls of each library used in the root of the project.

Hope this helps.

I know the topic is a couple years old now but since I was searching for a way to link the sfml lib in vs code and I first ended up here, I thought I would share this git repo I found, which works pretty well for me so far:

https://github.com/andrew-r-king/sfml-vscode-boilerplate

I'm not using SFML 2.5.1 though, so I had to bring a small change in the c_cpp_properties.json file (I am on Ubuntu 18.04 and installed sfml through package manager)

here my c_cpp_properties.json file:

{
    "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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!