Pkg-config for VS Code?

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…)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
"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"
}
]
}
</code>
<code>{ "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" } ] } </code>
{
    "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.

  • 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

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?

8

So, learned a few things here. Three files, all within the .vscode directory, manage the process.

  • launch.json deals with the “run and debug” process.
  • c_cpp_properties.json deals with intellisense but NOT compilation.
  • tasks.json deals with the build and compile 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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>-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
</code>
<code>-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 </code>
-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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
"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"
}
]
}
</code>
<code>{ "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" } ] } </code>
{
    "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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
"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"
}
</code>
<code>{ "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" } </code>
{
    "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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{
"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
}
</code>
<code>{ "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 } </code>
{
    "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
}

3

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”.

Found this from here originally and recently found this which shows the updated functionality.

1

You could do all that….

or in one line you can just add "gstreamer" to your vcpkg.json, run vcpkg install and you’d be done

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật