zip*_*zit 1 c gstreamer visual-studio-code
我希望使用 VS Code 在 Linux Virtualbox 中运行 GStreamer Hello World 示例。
Gstreamer安装说明请参见此处。
GStreamer HelloWorld 信息请参见此处。
手动 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 文件中。我不清楚具体如何做到这一点。
我从一个 launch.json 文件开始,我相信该文件是由 Microsoft 的 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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我看到的错误是? 无法打开源文件“gst/gst.h” 我不明白 launch.json 正在寻找什么。
编辑/评论:显然这不是一个新问题。
我只是没有看到明确的解决方案。DarkTrick 的解决方案有效,但相当丑陋。丑陋到足以将其推到 Visual Studio 而不是 VS Code。另一种选择是将 CMakeLists.txt 与 VS Code 结合使用。它使用多个 .vscode 文件,但至少它们是生成的,而不是仅仅被黑客攻击的。
还有其他人有一个简单的解决方案来使用pkg-config与 VS code 和 launch.json 吗?
So, learned a few things here. Three files, all within the .vscode directory, manage the process.
尽管我能够确定为了“运行”“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
Run Code Online (Sandbox Code Playgroud)
手动获取这些包含 (-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 控制文件。
启动.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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
任务.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"
}
Run Code Online (Sandbox Code Playgroud)
和 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5661 次 |
| 最近记录: |