Home Development Tools VSCode Vscode has a header file and cannot be compiled. Solution

Vscode has a header file and cannot be compiled. Solution

Mar 28, 2020 am 10:40 AM
vscode

Vscode has a header file and cannot be compiled. Solution

在使用VSCODE进行C语言程序设计时,如果用到了头文件声明函数,.c文件定义函数,在编译时尽管已经引用了相应的头文件,VSCODE文本编辑器也没有报错,但仍然无法编译。

错误提示如下:

d:/ComputerHomework/2019_winter/main.c:10: undefined reference to `ReadPathTkFile'

这是由于VSCODE实际上是一个文本编辑器,不是一个IDE,它不会自动链接项目通过头文件引用的.c文件。要解决这个问题,就要告诉编译器需要链接哪些文件。

解决方法

在当前路径下的.vscode文件夹中找到tasks.json,找到"args"属性,在其中"-g"后,"-o"前加入"${fileDirname}\\YourcFileName.c",每组字符串以逗号分隔。YourcFileName.c即项目中要参与编译的文件名。
样例如下(仅参考填写格式,具体参数不相同正常)

{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc.exe build active file",
            "command": "C:\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "${fileDirname}\\IstkFile.c",
                "${fileDirname}\\PrintQuestion.c",
                "${fileDirname}\\MarkingSystemLib.c",
                "${fileDirname}\\zqyLib.c",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
                
            ],
            "options": {
                "cwd": "C:\\mingw64\\bin"
            }
        }
    ],
    "version": "2.0.0"
}

推荐学习:vscode教程

The above is the detailed content of Vscode has a header file and cannot be compiled. Solution. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to install VSCode on Windows How to install VSCode on Windows Jul 27, 2025 am 03:16 AM

Gotohttps://code.visualstudio.comanddownloadtheWindowsUserInstaller.2.Runthe.exefile,allowchanges,andselectrecommendedoptionsincludingaddingtoPATHandcreatingadesktopshortcut.3.ClickFinishtolaunchVSCodeafterinstallation.4.Optionallyinstallusefulextens

How to use VSCode with WSL (Windows Subsystem for Linux) How to use VSCode with WSL (Windows Subsystem for Linux) Aug 01, 2025 am 06:26 AM

InstallWSLandaLinuxdistributionbyrunningwsl--installinPowerShellasAdministrator,thenrestartandsetuptheLinuxdistribution.2.Installthe"Remote-WSL"extensioninVSCodetoenableintegrationwithWSL.3.OpenaprojectinWSLbylaunchingtheWSLterminal,navigat

How to run Python script with arguments in VSCode How to run Python script with arguments in VSCode Jul 30, 2025 am 04:11 AM

TorunaPythonscriptwithargumentsinVSCode,configurelaunch.jsonbyopeningtheRunandDebugpanel,creatingoreditingthelaunch.jsonfile,andaddingthedesiredargumentsinthe"args"arraywithintheconfiguration.2.InyourPythonscript,useargparseorsys.argvtoacce

What is the difference between VSCode and Visual Studio What is the difference between VSCode and Visual Studio Jul 30, 2025 am 02:38 AM

VSCodeisalightweight,cross-platformcodeeditorwithIDE-likefeaturesviaextensions,idealforwebandopen-sourcedevelopment;2.VisualStudioisafull-featured,Windows-onlyIDEdesignedforcomplex.NET,C ,andenterpriseapplications;3.VSCodeperformsfasteronlower-endma

How to change font size in VSCode How to change font size in VSCode Jul 26, 2025 am 04:13 AM

TochangethefontsizeinVSCode,gotoFile>Preferences>Settings,searchfor"fontsize",andmodifythe"Editor:FontSize"value.2.Alternatively,manuallyeditthesettings.jsonfilebyopeningtheCommandPalette,selecting"Preferences:OpenSetti

How to debug unit tests in VSCode How to debug unit tests in VSCode Aug 01, 2025 am 06:12 AM

Createormodifylaunch.jsoninVSCodebyopeningtheRunandDebugview,selectingyourenvironment(e.g.,Python,Node.js),andconfiguringitforyourtestframework(e.g.,pytest,Jest).2.Setbreakpointsinyourtestfile,selectthedebugconfiguration,andstartdebuggingwithF5topaus

How to change the font size in vscode? How to change the font size in vscode? Aug 02, 2025 am 02:37 AM

TochangethefontsizeinVSCode,useoneofthesemethods:1.OpenSettingsviaCtrl ,(orCmd ,onMac),searchfor"fontsize",andadjustthe"Editor:FontSize"value.2.OpenSettings(JSON)fromtheCommandPalette,thenaddormodify"editor.fontSize":e.g

How to change the default terminal in VSCode How to change the default terminal in VSCode Jul 25, 2025 am 02:58 AM

Open the VSCode settings and enter the settings interface through Ctrl (macOS is Cmd ,); 2. Enter "terminaldefault" in the search bar and find the "Terminal›Integrated:DefaultProfile" option; 3. Select the preferred terminal from the drop-down menu, such as PowerShell, GitBash, WSL or zsh, etc.; 4. If the terminal is not listed, you can open the settings.json file and customize the path by adding terminal.integrated.profiles, such as setting GitBash or zsh; 5. After modification, close the existing terminal and press Ctrl

See all articles