Home > Blockchain >  How to add a command to the linker in Visual Studio Code
How to add a command to the linker in Visual Studio Code

Time:12-03

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

CodePudding user response:

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.

CodePudding user response:

Edit: The original post was edited and now it is clear the question was about VSCode. The below applies only to Visual Studio, so it should be ignored.

  • Right click on yout project and open the "Linker/Input" property page.
  • Under "Additional Dependencies" enter "gdiplus-lgdi32.lib".
  • If necessary, add the directory of the library to "Additional Library Directories". More details can be found here.
  • Related