首页 > 解决方案 > VSCode C++ 编译错误:如何链接附加库 (*.lib)?

问题描述

我正在设置 VS Code 环境 (Windows) 来编译 Visual Studio C 项目。在源文件中调用了一个附加/外部 *.lib 文件。并且在如图所示的目录中。该项目在 Visual Studio 中运行良好。但是当我在 VS Code 中编译它时,编译器在附加的 *.lib 中找不到函数。

Visual Studio C 项目的项目属性

task.json 和 c_cpp_properties.json 如下。

任务.json

{
// See https://go.microsoft.com/fwlink/?LinkId=733558 
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "type": "shell",
        "command": "g++",
        "args": [
            "-g",
            "${file}",
            "-I",
            "C:/PROGRAM FILES (X86)/NATIONAL INSTRUMENTS/SHARED/EXTERNALCOMPILERSUPPORT/C/INCLUDE",
            "-L",
            "C:/PROGRAM FILES (X86)/NATIONAL INSTRUMENTS/SHARED/EXTERNALCOMPILERSUPPORT/C/LIB32/MSVC",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "C:\\mingw64\\bin"
        }
    }
]
}

c_cpp_properties.json

{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**",
            "C:/PROGRAM FILES (X86)/NATIONAL INSTRUMENTS/SHARED/EXTERNALCOMPILERSUPPORT/C/INCLUDE"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "compilerPath": "C:\\mingw64\\bin\\g++.exe",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "gcc-x64",
        "browse": {
            "path": [
                "${workspaceFolder}/**",
                "C:/PROGRAM FILES (X86)/NATIONAL INSTRUMENTS/SHARED/EXTERNALCOMPILERSUPPORT/C/INCLUDE"
            ],
            "limitSymbolsToIncludedHeaders": true,
            "databaseFilename": ""
        }
    }
],
"version": 4
}

我可以像在 Visual Studio 中一样在 VS Code 环境中链接 *.lib 吗?

标签: c++visual-studio-codecompiler-errorsmingw

解决方案


你好我知道这太晚了,但我只是偶然发现了这个,尝试在“-o”之后添加路径


推荐阅读