1

I have been trying to link to my glfw3.lib that i have created by following this tutorial. This tutorial makes the project in visual studio. In visual studio, you can provide a path to your libraries folder and simply link to it in linker setting but how do you link to external libraries in VS CODE.

This is my c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/Dependencies/include",
                "${workspaceFolder}/Dependencies/lib"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "\"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe\"",
            "cStandard": "c11",
            "intelliSenseMode": "gcc-x64",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

and the following is my task.json file

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\build\\${fileBasenameNoExtension}.exe",
            ],
            "options": {
                "cwd": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ]
}
Arbaz Irshad
  • 749
  • 2
  • 9
  • 22
  • 1
    Linking against libraries can be done using the `args` property in the `task.json` adding the corresponding compiler command line arguments. – t.niese Dec 27 '19 at 18:45
  • Thanks for the help. The files now compiled successfully and i understood more of how to compile my code and about vscode. So, the config file is for the editor and task file is for compiler. – Arbaz Irshad Dec 27 '19 at 19:14
  • 1
    If you start to create a larger project I wouldn't use these files directly, but use a tool like CMake instead, this allows you to stay independent from the IDE. CMake is able to create project files for the most common IDEs that don't have CMake integration. And VSCode has an extension to CMake integration. CMake is not the only tool out there that does this but is probably the most common one (at least one of them). – t.niese Dec 28 '19 at 07:47

0 Answers0