Home > Back-end >  Vscode compiler header file problem "undefined reference... "
Vscode compiler header file problem "undefined reference... "

Time:11-17

Header and the main program files in the same folder, no wavy lines in the preprocessor directive and errors, but the runtime prompts "undefined reference... "Error, who help me

CodePudding user response:

This is a link error,

Need to rely on libraries, is added in the link options

CodePudding user response:

Guess is not to come out or guess is not complete, suggested that the original poster stick all the code and the corresponding compiler hint ~

CodePudding user response:

https://code.visualstudio.com/docs/cpp/config-msvc
From the main menu, choose Terminal & gt; Configure the Default Build Task. In the dropdown can, which will display the tasks a dropdown can listing various predefined Build tasks for c + + compilers. Choose cl. Exe Build active file, which will Build the file that is currently displayed In the editor (active).

The Tasks of c + + build dropdown can

This will create a tasks. The json file in a. vscode folder and open it in the editor.

Your new tasks. The json file should look similar to the json below:

{
"Version" : "2.0.0,"
"Tasks" : [
{
"Type" : "shell",
"Label" : "cl. Exe build active file",
"Command" : "cl. Exe,"
"Args" : [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname} \ \ ${fileBasenameNoExtension}. Exe",
"${file}" ,
"/link/LIBPATH: additional dependent libraries. Lib directory",
"/link/IMPLIB: additional dependent libraries. Lib"//zhao4zhong1 add (^_^)
,
"ProblemMatcher" : "$msCompile"],
"Group" : {
"Kind" : "build,"
"IsDefault" : true
}
}
]
}
The command setting specifies The program to run; in this case that is "cl.exe". The args array specifies the command-line arguments that will be passed to cl.exe. These arguments must be specified in the order expected by the compiler. This task tells the C++ compiler to take the active file (${file}), compile it, and create an executable file (/Fe: switch) in the current directory (${fileDirname}) with the same name as the active file but with the .exe extension (${fileBasenameNoExtension}.exe), resulting in helloworld.exe for our example.

CodePudding user response:

Put in the red should be changed to
"/link/LIBPATH: additional dependent libraries. Lib directory",
"Additional dependent libraries/link. Lib"//zhao4zhong1 add (^_^)
  • Related