I was hoping to run GStreamer Hello World example in a Linux Virtualbox with VS Code.
Gstreamer install directions here.
GStreamer HelloWorld info here.
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. 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. 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. I did not add a CMakeLists file. There are no other extensions installed within VS Code.
My current launch.json file: (test #17 or so...)
{
"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.
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. Ugly enough to push one over to Visual Studio instead of VS Code. Another option is to use CMakeLists.txt with VS Code. That uses multiple .vscode files, but at least they are generated as opposed to just hacked.
Anybody else got a simple solution to use pkg-config with VS code and launch.json?
So, learned a few things here. Three files, all within the .vscode directory, manage the process.
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.
Instead, just run $ pkg-config --cflags --libs gstreamer-1.0
in the terminal (without quotes). That shell command returns:
-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. 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. tasks.json and launch.json will propagate when you try to "Run and debug". And you can generate the c_cpp_properties.json file by finding an intellisense red squiggly line error. Look for the light bulb icon, select it. Add xxx or edit xxx to generate the c_cpp_properties.json file within your project for you.
And although its a bit lengthy, here are the three .json control files for GStreamer hello world.
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"
}
and 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
}