简体   繁体   English

用于 VS 代码的 Pkg-config?

[英]Pkg-config for VS Code?

I was hoping to run GStreamer Hello World example in a Linux Virtualbox with VS Code.我希望在带有 VS Code 的 Linux Virtualbox 中运行 GStreamer Hello World 示例。

Gstreamer install directions here. Gstreamer 安装说明在这里。
GStreamer HelloWorld info here. GStreamer HelloWorld 信息在这里。

The manual C build/compile command is $ gcc basic-tutorial-1.c -o basic-tutorial-1 'pkg-config --cflags --libs gstreamer-1.0' Works great that way.手动 C 构建/编译命令是$ gcc basic-tutorial-1.c -o basic-tutorial-1 'pkg-config --cflags --libs gstreamer-1.0'方式。 But, I was hoping to use Visual Studio Code, and I'm trying to push the 'pkg-config --cflags --libs gstreamer-1.0' content into my launch.json file.但是,我希望使用 Visual Studio Code,并且正在尝试将“pkg-config --cflags --libs gstreamer-1.0”内容推送到我的 launch.json 文件中。 It's not clear to me on how exactly to do that.不清楚如何确切地做到这一点。

I started with a launch.json file which I believe was created by the C/C++ plugin from Microsoft within VS Code.我从一个 launch.json 文件开始,我相信它是由微软的 C/C++ 插件在 VS Code 中创建的。 I did not add a CMakeLists file.我没有添加 CMakeLists 文件。 There are no other extensions installed within VS Code. VS Code 中没有安装其他扩展。

My current launch.json file: (test #17 or so...)我当前的 launch.json 文件:(测试 #17 左右...)

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [{ "name": "pkg-config", "value": " --cflags"},{"name": "--libs", "value":  "gstreamer-1.0"}],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

The error I'm seeing?我看到的错误? cannot open source file "gst/gst.h" I don't understand what launch.json is looking for.无法打开源文件“gst/gst.h”我不明白 launch.json 正在寻找什么。

Edit/Comment: Apparently this is not a new issue.编辑/评论:显然这不是一个新问题。

And I'm just not seeing a clear solution.而且我只是没有看到明确的解决方案。 The solutions from DarkTrick work, but are pretty ugly. DarkTrick 的解决方案有效,但非常难看。 Ugly enough to push one over to Visual Studio instead of VS Code.丑到将一个推到 Visual Studio 而不是 VS Code 上。 Another option is to use CMakeLists.txt with VS Code.另一种选择是将 CMakeLists.txt 与 VS Code 一起使用。 That uses multiple.vscode files, but at least they are generated as opposed to just hacked.这使用了多个 .vscode 文件,但至少它们是生成的,而不是仅仅被黑客入侵。

Anybody else got a simple solution to use pkg-config with VS code and launch.json?其他人有一个简单的解决方案来使用pkg-config和 VS 代码并启动。json?

So, learned a few things here.所以,在这里学到了一些东西。 Three files, all within the.vscode directory, manage the process.三个文件都在 .vscode 目录中,用于管理进程。

  • launch.json deals with the "run and debug" process. launch.json 处理“运行和调试”过程。
  • c_cpp_properties.json deals with intellisense but NOT compilation. c_cpp_properties.json 处理智能感知但不处理编译。
  • tasks.json deals with the build and compile process. tasks.json 处理构建和编译过程。

Although I was able to determine that in order to "run" the 'pkg-config --cflags --libs gstreamer-1.0' it needed to be surrounded in double quotes, then reverse single quote, I could never get any of the tooling to work harmoniously that way.虽然我能够确定为了“运行”“pkg-config --cflags --libs gstreamer-1.0”它需要用双引号括起来,然后反转单引号,但我永远无法获得任何工具这样和谐地工作。

Instead, just run $ pkg-config --cflags --libs gstreamer-1.0 in the terminal (without quotes).相反,只需在终端中运行$ pkg-config --cflags --libs gstreamer-1.0 (不带引号)。 That shell command returns:该 shell 命令返回:

-pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0

Manually grab those include (-I) and library (-l) elements and place them in the appropriate places within tasks.json and c_cpp_properties.json files.手动抓取包含 (-I) 和库 (-l) 元素并将它们放置在 tasks.json 和 c_cpp_properties.json 文件中的适当位置。 And that works.那行得通。 I can use intellisense to understand the code, I can debug step thru the content.我可以使用智能感知来理解代码,我可以逐步调试内容。

There were a couple of tricks along the way.一路上有几个技巧。 Use VS Code to generate each of the three files.使用 VS Code 生成这三个文件中的每一个。 tasks.json and launch.json will propagate when you try to "Run and debug". tasks.json 和 launch.json 将在您尝试“运行和调试”时传播。 And you can generate the c_cpp_properties.json file by finding an intellisense red squiggly line error.您可以通过查找智能感知红色波浪线错误来生成 c_cpp_properties.json 文件。 Look for the light bulb icon, select it.寻找灯泡图标,select。 Add xxx or edit xxx to generate the c_cpp_properties.json file within your project for you.添加 xxx 或编辑 xxx 以在您的项目中为您生成 c_cpp_properties.json 文件。

VSCode 警告 1

VSCode 智能感知辅助 2

And although its a bit lengthy, here are the three.json control files for GStreamer hello world.虽然有点长,这里是 GStreamer hello world 的三个.json 控制文件。

launch.json:发射.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

tasks.json:任务.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-pthread",
                "-I/usr/include/gstreamer-1.0",
                "-I/usr/include/glib-2.0",
                "-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
                "-lgstreamer-1.0",
                "-lgobject-2.0",
                "-lglib-2.0"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

and c_cpp_properties.json:和 c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/gstreamer-1.0/**",
                "/usr/include/glib-2.0",
                "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64",
            "compilerArgs": [
                "-pthread",
                "-lgstreamer-1.0",
                "-lgobject-2.0",
                "-lglib-2.0"
            ]
        }
    ],
    "version": 4
}

I'm writing this as an answer because I don't have enough reputation to comment (literally just made an account).我写这个作为答案是因为我没有足够的声誉来发表评论(实际上只是创建了一个帐户)。 In case you have not stumbled upon this already, you can directly run the pkg-config command in tasks.json by using "`pkg-config --libs --cflags gstreamer-1.0`" in "args".如果您还没有偶然发现这一点,您可以直接在 tasks.json 中运行pkg-config命令,方法是在“args”中使用"`pkg-config --libs --cflags gstreamer-1.0`" ”。

Found this from here originally and recently found this which shows the updated functionality.最初从这里找到这个,最近发现这个显示了更新的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM