How to add a command to the linker in Visual Studio Code

Viewed 1258

I try to compile my C++ code in Visual Studio Code but every time I get the following error:

undefined reference to ...

I have to add -lgdiplus-lgdi32 to my compiler/linker options. How can I do this in Visual Studio?

This is a part of my task.json file:

"args": [
    "-fdiagnostics-color=always",
    "-g",
    "${file}",
    "-o",
    "${fileDirname}\\${fileBasenameNoExtension}.exe",
    "-lgdiplus",
    "-lgdi32"
],
1 Answers

Assuming you're under linux(otherwise the process only shows different paths/compilers) Under the .vscode folder, there should be a task.json file. You should find something similar to:

"command": "/usr/bin/g++",
"args": [
    "-fdiagnostics-color=always",
    "-g",
    "${file}",
    "-o",
    "${fileDirname}/${fileBasenameNoExtension}"
 ],

Add your arguments to the argument list, enjoy

If there's no file named like that nor you have the folder .vscode in your workspace, click F5 and follow the instructions, and this will generate the necessary files for you.

Related