vscode在编译时找不到标题,而Intellisense可以 [英] vscode cannot find header when compile while Intellisense can

查看:609
本文介绍了vscode在编译时找不到标题,而Intellisense可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题已更新: 我正在尝试使用C/C ++扩展在vscode上构建一个c ++项目.编译器抱怨找不到头文件(实际上是增强头文件).我已经包含了boost的根文件夹的路径,并且Intellisense也能够解析头文件路径,但不能解析编译器.我检查了源文件中包含的标头是否在文件系统中的相应路径中.有什么解决方法可以使编译器看到包含标头?

Question Updated: I'm trying to build a c++ project on vscode using the C/C++ extension. The compiler complains about not finding header files (actually boost headers). I have included path to the root folder of boost, and Intellisense is also able to parse the header paths, but not the compiler. I checked the included header in my source is in the corresponding path in my filesystem. Is there any solution to make the compiler see the include headers?

这是我的c_cpp_properties.json文件:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Users/zz_ro/Documents/source/boost_1_70_0"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:/mingw/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

这是我的helloworld.cpp文件:

#include "boost/math/constants/constants.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
#include <iostream>
#include <limits>
int main()
{
    using boost::multiprecision::cpp_dec_float_50;
    cpp_dec_float_50 seventh = cpp_dec_float_50(1) / 7;
    std::cout.precision(std::numeric_limits<cpp_dec_float_50>::digits10);
    std::cout << seventh << std::endl;
}

这是编译器的输出:

helloworld.cpp:1:46: fatal error: boost/math/constants/constants.hpp: No such file or directory
 #include "boost/math/constants/constants.hpp"
                                              ^
compilation terminated.
The terminal process terminated with exit code: 1

如果我将tasks.json从更改为

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hello world",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "helloworld.cpp",
                "-o",                               
                "helloworld"                
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hello world",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "-IC:\\Users\\zz_ro\\Documents\\source\\boost_1_70_0", 
                "helloworld.cpp",
                "-o",                               
                "helloworld"                
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

只需手动将包含路径作为参数传递给g++.exe,编译就会通过.这使我感到困惑,在该教程中( vscode教程)没有提及通过命令行参数手动将包含路径插入g++.exe的情况,所有这些都应该通过修改c_cpp_property.json中的includePath变量来完成.是我误解了本教程,还是没有正确设置includePath值?

by just manually passing the include path as an argument to g++.exe and the compilation will go through. It confuses me that in the tutorial (vscode tutorial) there is no mention about manually inserting include path to g++.exe via command line parameters, where all of these are supposed to be done by modifying the includePath variable in c_cpp_property.json. Did I misunderstand the tutorial or I didn't set the includePath value properly?

推荐答案

c_cpp属性用于智能感知.它不用于编译.编译器之所以存在,仅是因为它被要求查找用于系统标头的默认包含路径.

c_cpp properties is for intellisense. It is not used for compiling. The compiler is there only because it is queried to find the default include paths it uses for system headers.

任务定义了构建任务的运行方式.

The tasks defines how the build task runs.

Vscode不能将两者连接起来.

Vscode doesn't connect the two.

这篇关于vscode在编译时找不到标题,而Intellisense可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆