首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译时vscode找不到头,而Intellisense可以找到头。

编译时vscode找不到头,而Intellisense可以找到头。
EN

Stack Overflow用户
提问于 2019-05-12 03:43:14
回答 1查看 20.8K关注 0票数 4

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

这是我的c_cpp_properties.json文件:

代码语言:javascript
复制
{
    "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文件:

代码语言:javascript
复制
#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;
}

下面是编译器的输出:

代码语言:javascript
复制
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更改为

代码语言:javascript
复制
{
    // 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
            }
        }
    ]
}

代码语言:javascript
复制
{
    // 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值?

EN

Stack Overflow用户

回答已采纳

发布于 2019-05-12 14:56:13

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

这些任务定义构建任务的运行方式。

Vscode并没有将两者连接起来。

票数 10
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56096045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档