title: VS Code C/C++ configuration for GTK development
body: <p>I am trying to set up a friendly environment for C/C++ programming in VS Code on Linux Ubuntu. For years I've been using Visual Studio and Code Blocks, however VS Code set up is so unclear that I can hardly understand the documentation topics. At the moment I am trying to compile few &quot;hello world&quot; programs so it shouldn't be hard.</p>
  <p>Lets say I am trying to build and run GTK-3 <a href="https://developer.gnome.org/gtk3/stable/gtk-getting-started.html" rel="nofollow noreferrer">hello world program</a>. The command line instructions to do this is:</p>
  <pre><code>gcc hello_world.c `pkg-config --cflags --libs gtk+-3.0`
  </code></pre>
  <p>which works just perfectly when used from bash. So first I have created a configuration <code>c_cpp_properties.json</code> called <code>GTK-devel</code> which is supposed to compile this. The json file content is:</p>
  <pre><code>{
      &quot;configurations&quot;: [
          {
              &quot;name&quot;: &quot;GTK-devel&quot;,
              &quot;includePath&quot;: [
                  &quot;${workspaceFolder}/**&quot;
              ],
              &quot;defines&quot;: [],
              &quot;compilerPath&quot;: &quot;/usr/bin/gcc&quot;,
              &quot;cStandard&quot;: &quot;c11&quot;,
              &quot;cppStandard&quot;: &quot;c++14&quot;,
              &quot;intelliSenseMode&quot;: &quot;linux-gcc-x64&quot;,
              &quot;compilerArgs&quot;: [
                  &quot;`pkg-config --cflags --libs gtk+-3.0`&quot;
              ]
          }
      ],
      &quot;version&quot;: 4
  }
  </code></pre>
  <p><strong>And here comes the first question</strong>: What is a configuration in VS Code? In Visual Studio or Code::Blocks similar things were intuitively clear and undesrtandable - just set up everything you need and then choose it somewhere (menu, dialog,...) before compiling. I guess that in VS Code it is something different, the <a href="https://code.visualstudio.com/docs/cpp/config-linux#_cc-configurations" rel="nofollow noreferrer">docs</a> don't explain that at all - it just says one can create a configuration, but does not mention how to use it. Moreover there is no place in which one can select it (terminals, tasks, etc), nor where is is even visible anywhere in menu etc.</p>
  <p><strong>Second question</strong> concerns tasks. So if configuration approach failed I've decided to set up a task which I can clearly access from main menu. The <code>tasks.json</code> file has the following content:</p>
  <pre><code>{
      &quot;version&quot;: &quot;2.0.0&quot;,
      &quot;tasks&quot;: [
          {
              &quot;type&quot;: &quot;cppbuild&quot;,
              &quot;label&quot;: &quot;C/C++: gcc compilation&quot;,
              &quot;command&quot;: &quot;/usr/bin/gcc `pkg-config --cflags --libs gtk+-3.0`&quot;,
              &quot;args&quot;: [
                  &quot;-g&quot;,
                  &quot;${file}&quot;,
                  &quot;-o&quot;,
                  &quot;${fileDirname}/${fileBasenameNoExtension}&quot;
              ],
              &quot;options&quot;: {
                  &quot;cwd&quot;: &quot;${workspaceFolder}&quot;
              },
              &quot;problemMatcher&quot;: [
                  &quot;$gcc&quot;
              ],
              &quot;group&quot;: &quot;build&quot;,
              &quot;detail&quot;: &quot;kompilator: /usr/bin/gcc GTK3&quot;
          }
      ]
  }
  </code></pre>
  <p>When I choose from menu <code>Terminal -&gt; Run build task -&gt; C/C++: gcc compilation</code> everything seems to be fine in terms of called instructions but there are missing libs errors (which are included and present in the system):</p>
  <pre class="lang-sh prettyprint-override"><code>&quot;/usr/bin/gcc `pkg-config --cflags --libs gtk+-3.0`&quot; -g /home/user/Programming/hello_world/hello_world.c -o /home/user/Programming/hello_world/hello_world
  /bin/sh: 1: /usr/bin/gcc -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0: not found
  </code></pre>
  <p><strong>Here the third question arises</strong>: Again the <a href="https://code.visualstudio.com/docs/editor/integrated-terminal" rel="nofollow noreferrer">docs</a> don't really explain what is a terminal. It says that it defaults to <code>$SHELL</code>, but if so, why the libs are not visible to the compiler?</p>
  <p><strong>So the final question is</strong>: Is VS Code a real IDE or it is just a marketing around it that it can be used to do many different things in one place, but in reality it is better to use dedicated tool for each language etc. as setup issues will succesfully distract you from what you are really supposed to do?</p>