如何解决VS Code 的 Pkg-config?
我希望使用 VS Code 在 Linux VirtualBox 中运行 GStreamer Hello World 示例。
Gstreamer install directions here.
GStreamer HelloWorld info here.
手动 C 构建/编译命令是 $ gcc basic-tutorial-1.c -o basic-tutorial-1 'pkg-config --cflags --libs gstreamer-1.0'
那样很好用。但是,我希望使用 Visual Studio Code,并且我正在尝试将 'pkg-config --cflags --libs gstreamer-1.0' 内容推送到我的 launch.json 文件中。我not clear决定如何做到这一点。
我从一个 launch.json 文件开始,我相信它是由微软的 C/C++ 插件在 VS Code 中创建的。我没有添加 CMakeLists 文件。 VS Code 中没有安装其他扩展。
我当前的 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"
}
]
}
我看到的错误? 无法打开源文件“gst/gst.h”我不明白launch.json在寻找什么。
- https://www.javaer101.com/en/article/37220391.html
- (How to configure VSCode for GTK3 for intellisense / build / debug and g++)
- VS Code C/C++ configuration for GTK development
- https://www.reddit.com/r/vscode/comments/joozcp/escaping_backticks_command_substitution/
- https://www.reddit.com/r/vscode/comments/m66kpr/how_to_add_pkgconfig_compiler_arguments_to_vscode/
- How to use `pkg-config gtkmm-3.0 --cflags --libs` in the Visual Studio Code
我只是没有看到明确的解决方案。 DarkTrick 的解决方案有效,但非常难看。丑到可以将一个推到 Visual Studio 而不是 VS Code。另一种选择是在 VS Code 中使用 CMakeLists.txt。这使用了多个 .vscode 文件,但至少它们是生成的,而不是被黑客入侵。
有没有其他人有一个简单的解决方案来将 pkg-config 与 VS 代码和 launch.json 结合使用?
解决方法
所以,在这里学到了一些东西。三个文件,都在 .vscode 目录下,管理这个过程。
- launch.json 处理“运行和调试”过程。
- c_cpp_properties.json 处理智能感知,但不处理编译。
- tasks.json 处理构建和编译过程。
虽然我能够确定为了“运行”'pkg-config --cflags --libs gstreamer-1.0',它需要用双引号括起来,然后反转单引号,但我永远无法得到任何以这种方式和谐工作的工具。
相反,只需在终端中运行 $ pkg-config --cflags --libs gstreamer-1.0
(不带引号)。该 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
手动抓取那些包含 (-I) 和库 (-l) 元素并将它们放置在 tasks.json 和 c_cpp_properties.json 文件中的适当位置。这有效。我可以使用智能感知来理解代码,我可以通过内容调试步骤。
一路上有几个技巧。使用 VS Code 生成三个文件中的每一个。当您尝试“运行和调试”时,tasks.json 和 launch.json 将传播。您可以通过查找智能感知红色波浪线错误来生成 c_cpp_properties.json 文件。寻找灯泡图标,选择它。添加 xxx 或编辑 xxx 以在您的项目中为您生成 c_cpp_properties.json 文件。
虽然有点冗长,但这里是 GStreamer hello world 的三个 .json 控制文件。
launch.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:
{
"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"
}
和 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","-lglib-2.0"
]
}
],"version": 4
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。