When I try to create a C/C++ source file

touch test.cpp

Usually it will generate a file which type is C source code file. But today I got a plain text file. enter image description here

And I write a simple program in it like:

#include <stdio.h>
int main()
{ printf("hello");}

Then I use G++ to compile it:

g++ test.cpp -o test

However, I got a sharedlib file instead of executable file. enter image description here

And I can run the sharedlib file and get the correct ouput:


In the past, I can directly create a C++ source code file and this file type is easy to edit in vscode. But the plain text file is not comfortable for me.

So the two questions really bother me:

  1. why my Ubuntu can not recognize C/C++ source code file correctly?
  2. why I get a sharedlib file by using default g++ command?

1 Answer 1


The command touch test.cpp creates a plain text file in Ubuntu 18.04 by default as it should. Next try opening test.cpp in Gedit text editor and pasting the following code as you did:

#include <stdio.h>
int main()
{ printf("hello");}

Save the file. Now look at the right side of the bottom panel in Gedit and you will see that the file type has changed to C++. Right-click test.cpp and select Properties and you will see that the Type has changed to C++ source code (text/x-c++src). You should have no problem running test.cpp which now has type C++ source code (text/x-c++src) in Visual Studio Code.

If you want to get an executable/x-sharedlib file (which has a lavender diamond-shaped icon with two gears in Ubuntu 18.04) instead of an application/x-sharedlib file, then you need to create a new project for the test.cpp source code in Visual Studio Code before running it.

  • Its type becomes c++ source code file. But when I edit it in VSCode, if I delete the #include <stdio.h> , and then I try to rewrite this code, the autocomplete doesn't have reaction. In the past, when I input #incl , the autocomplete will help me to finish #include
    – pangbryant
    Jun 28, 2018 at 10:42
  • That's an unexpected result because whenever you edit a C++ source code file in Visual Studio Code the autocomplete functionality should work properly, especially if you have already saved the C++ file at least once in Visual Studio Code.
    – karel
    Jun 28, 2018 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .