最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How configure Visual Studio Code for develop GTK3 application using c - Stack Overflow

programmeradmin0浏览0评论

I would like to developing a GTK3 application using Visual Studio Code, using like language programming c. I searched a lot but i did not found how to configure VS Code in relation to GTK3.

Today I found a solution that is really near a what I was searching.

Your project is in a folder that we can call PROJECT. In this folder there are several sub-folders: src: where you put all yours source code .c hdr: where you put all your headers code .h .vscode where you put 3 files json of configuration of VScode.

In Visual Studio Code you have to add at least the C/C++ component.

In .vscode you have to put the following files:

c_cpp_properties.json

 {
     "configurations": [
         {  
             "name": "Linux",
             "includePath": [
                 "${workspaceFolder}/**",
                 "/usr/include",
                 "/usr/include/cairo",
                 "/usr/include/gtk-3.0",
                 "/usr/include/glib-2.0",
                 "/usr/lib/x86_64-linux-gnu/glib-2.0/include",
                 "/usr/include/pango-1.0",
                 "/usr/include/harfbuzz",
                 "/usr/include/gdk-pixbuf-2.0",
                 "/usr/include/atk-1.0",
                 "/usr/include/gdk-pixbuf-2.0",
                 "/usr/include/pixman-1",
                 "/usr/include/freetype2",
                 "/usr/include/libpng16",
                 "/usr/include/uuid"
             ],
             "defines": [],
             "compilerPath": "/usr/bin/gcc",
             "cStandard": "c11",
             "cppStandard": "c++17",
             "intelliSenseMode": "linux-gcc-x64"
         }
     ],
     "version": 4
 }

tasks.json

 {
     "version": "2.0.0",
     "tasks": [
         {
             "label": "Compila GTK3 + Cairo + GLib + Pango + Harfbuzz + Gdk-Pixbuf + ATK",
             "type": "shell",
             "command": "bash",
             "args": [
                 "-c",
                 "gcc -g src/*.c -o APP -I. -Ihdr -I/usr/include/cairo -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -lm -rdynamic $(pkg-config --cflags --libs gtk+-3.0 cairo glib-2.0 pango harfbuzz gdk-pixbuf-2.0 atk-1.0)"
             ],
             "group": {
                 "kind": "build",
                 "isDefault": true
             },
             "problemMatcher": ["$gcc"]
         }
     ]
 }

launch.json

 {
     "version": "0.2.0",
     "configurations": [
         {
             "name": "Debug GTK3 App",
             "type": "cppdbg",
             "request": "launch",
             "program": "${workspaceFolder}/APP",
             "args": [],
             "stopAtEntry": false,
             "cwd": "${workspaceFolder}",
             "environment": [],
             "externalConsole": false,
             "MIMode": "gdb",
             "setupCommands": [
                 {
                     "description": "Enable pretty-printing for gdb",
                     "text": "-enable-pretty-printing",
                     "ignoreFailures": true
                 }
             ] 
         }
     ]
 }

Warning in my UBUNTU box there is the following file: /usr/lib/x86_64-linux-gnu/pkgconfig/atk.pc but VSCode search for atk-1.0.pc If you are in my conditions the possible solution is a symbolic link: sudo ln -s /usr/lib/x86_64-linux-gnu/pkgconfig/atk.pc /usr/lib/x86_64-linux-gnu/pkgconfig/atk-1.0.pc

In this configuration the executable is in the PROJECT folder. If you want you can change the location of APP modifying the tasks.json where is written: ..."gcc -g src/*.c -o APP...

remember to to the same in the launch.json

Now you can compile the code with CTRL+SHIFT+b and you can debug the code with F5 PS: Using an installation realized with SNAP the compilation finish with error, so, please, prefers the other, a bit more long, installation that end with sudo apt install code.

That's all!

发布评论

评论列表(0)

  1. 暂无评论