VS Code上有没有办法导入Makefile项目? [英] Is there a way on VS Code to import Makefile projects?

查看:2407
本文介绍了VS Code上有没有办法导入Makefile项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我可以从现有的Makefile中自动填充c_cpp_properties.json吗?

As the title said, can I populate automatically c_cpp_properties.json from an existing Makefile?

对于其他尝试导入makefile的人,我发现了一组脚本,这些脚本完全可以实现我想要实现的功能,即通过VS Code管理STM32嵌入式项目.如果您深入到scripts文件夹,则可以找到make解析器和VSCode项目文件填充器.

For others trying to import makefiles, I have found a set of scripts that perform exactly what I wanted to achieve, the management of STM32 embedded projects through VS Code. If you dig into the scripts folder you can find the make parser and the VSCode project files populator.

在这里回购,尽情享受吧!

推荐答案

此答案可能不会完全为您提供所需的内容,但希望它可以帮助您设置VS Code环境.

This answer may not entirely give you what you want, but hopefully it helps you setting up your VS Code environment.

在问题标题中,您提到"Makefile项目",这表明您有一种错误的印象,即(GNU)Makefile以类似于Visual Studio项目文件的方式捕获项目设置. Makefile不能那样工作,并且对您的问题的简短回答是否",似乎没有一种方法可以将"Makefile"导入"VS Code",并自动在c_cpp_properties.json文件中设置值.

In your question title, you mention "Makefile projects", which is an indication that you have the wrong impression that (GNU) Makefiles capture project settings in a way similar to Visual Studio project files do. Makefiles do not work like that and the short answer to your question is No, there does not seem to be a way to "import" Makefiles into VS Code and have it automatically set values in your c_cpp_properties.json file.

话虽如此,根据您工具链中的其他元素,还有一些其他机制可以帮助您根据情况开始使用VS Code.

Having said that, there are some other mechanisms that may help you getting started with VS Code in your situation, depending on the other elements you have in your toolchain.

VS Code的前提是它在文件系统中打开一个或多个目录.这样做时,它将自动扫描其所有子目录,显示树并进行整理(如果启用)以检测问题.实际上,需要手动将包含目录添加到您的c_cpp_properties.json文件中,但是要将所有子目录递归添加到包含目录列表中,则可以使用表达式

VS Code works with the premise that it opens one or more directories in your file system. When you do so, it will automatically scan all its subdirectories, display the tree and do linting (if enabled) to detect problems. Indeed, include directories need to be added manually to your c_cpp_properties.json file but to add all your subdirectories recursively to the list of include directories, you can use the expression

"${workspaceRoot}/**"

作为includePath设置中的元素之一.请参阅博客文章

as one of the elements in your includePath setting. See the blog post Visual Studio Code C/C++ extension May 2018 Update – IntelliSense configuration just got so much easier! for more details. That often resolves a lot of the missing symbols. If you are using external or 3rd party libraries as well, then you have to add those to your includePath setting manually, there is no way around that.

此外,您可以根据自己的喜好创建VS代码任务来执行make命令.此处说明:通过任务"与外部工具集成. Microsoft C/C ++扩展带有一组所谓的problemMatchers可以解析命令的输出,并可以为某些已知的编译器解释该输出.您将看到超链接,其中包含错误和警告,可直接导航到代码中的关联位置.

Additionally, you can create VS Code Tasks to execute your make command to your liking. This is explained here: Integrate with External Tools via Tasks. The Microsoft C/C++ Extension comes with a set of so-called problemMatchers that parse the output of your command and can interpret that for certain known compilers. You will see hyperlinks for errors and warning to navigate directly to the associated location in your code.

此类任务的示例可能如下所示:

An example of such a Task may look like this:

    {
        "label": "Build All Debug",
        "type": "shell",
        "command": "make -f path/to/Makefile DEBUG=1",
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "presentation": {
            "reveal": "always",
            "panel": "new"
        },
        "problemMatcher": [
            "$gcc"
        ]
    }

这篇关于VS Code上有没有办法导入Makefile项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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