How to create a .desktop to a C program? [closed]
So I'm trying to execute a C terminal program just by double clicking it. I'm trying to do that through a .desktop file
- The desktop file has permission to execute as a file and it's in my desktop.
- The program is named teste, wait for User input and it's in the /home/vithor/
- I'm Using the PopOs ( it is a "ubuntu distro" );
- I already allowed executable to launch in the nautilus configs;
[Desktop Entry]
Version=1.0
Name=ProgramName
Comment=This is my comment
Exec=/home/vithor/teste
Icon=/home/vithor/Pictures/Icons/books.png
Terminal=true
Type=Application
Categories=Utility;
~
But it's not working, what am I doing wrong? Or what alternative do I have to run a C program just by clicking it?
I am assuming the name of the program is teste
, and it is located at your home folder.
-
Remove
#!/usr/bin/env bash
from the first line. The first line should be[Desktop Entry]
-
Change the
Exec
entry toExec=/home/vithor/teste
-
Change the last line to
Categories=Utility
-
Mark the .desktop file as executable with the command
chmod +x /path/to/file.desktop
.
Now it should work when you double click it.
However, if the C program is supposed to print in the terminal and do nothing else, then it would print the results and would quickly close the terminal, and you won't be able to see anything. In such a case, change the source so that it waits for you to enter some character before closing.
Example code:
#include <stdio.h>
void main(){
// your code here
int a;
printf("enter any character to terminate: ");
scanf("%d",&a);
}
Now compile the code with
gcc path/to/source.c -o teste