I'm using Ubunru 15.04
GCC : 4.9.2
I usually use this command to compile my cpp files :
g++ /path/file.cpp -o /path/output
and it's cool ! so I made this into a shortcut with
.desktop
file format and make it executable and it works just fine !!
now I need to make a single shortcut to compile the cpp file and run the output
I simply tried :
g++ file.cpp -o output && /output
but this didn't work and giving Permission Denied when I try to run the .desktop file in terminal
ebram96@ebram96-jj:~$ '/path/shortcut.desktop'
/path/shortcut.desktop: line 1: [Desktop: command not found
/path/shortcut.desktop: line 2: run: command not found
/path/shortcut.desktop: line 3: /path/file.cpp: Permission denied
here is my .desktop file :
[Desktop Entry]
Name=compile&run
Exec=g++ /path/code.cpp -o /path/output && /path/output
Terminal=true
Type=Application
I simply tried :
g++ file.cpp -o output && ./output
I tried editing /etc/sudoers file adding these lines it also didn't work :
my_username ALL = NOPASSWD: /path/shortcut.desktop
my_username ALL = NOPASSWD: /path/
my_username ALL = NOPASSWD: /same_shortcut_path/output
Try adding the following to your
~/.bashrc
file:This creates an alias that can be executed from the terminal.
The function name / command i.e.
cr
can be replaced if you wish.To execute run:
cr file.cpp
You can't start a desktop file in this way. Move your desktop file into
~/.local/share/applications
and usegtk-launch
or start it via Unity/GNOME Shell ...In your case, an alias would be the better solution
Open your
.profile
in an editoradd a line like this
logout and re-login or use
Use the command (alias) with a simple
Create a bash function (to add in your
.bashrc
or.zshrc
):Then you can run
run-c++ ./whatever-path/to/program.cpp
.