Solved Creating a link to an executable

Solved issue

CaffeineAddict

Well-Known Member
Joined
Jan 21, 2024
Messages
1,656
Reaction score
1,156
Credits
13,707
I have downloaded a self-contained game called OpenTTD and have extracted the archive into /opt directory.
The contents of the extracted game directory are as follows:

Bash:
ls -l /opt/openttd-14.1-linux-generic-amd64/
total 57936
drwxr-xr-x 2 root root     4096 svi   3 23:06 ai
drwxr-xr-x 2 root root     4096 svi   3 23:06 baseset
-rw-r--r-- 1 root root   622939 svi   3 22:51 changelog.txt
-rw-r--r-- 1 root root    14396 svi   3 22:51 CONTRIBUTING.md
-rw-r--r-- 1 root root    18023 svi   3 22:51 COPYING.md
-rw-r--r-- 1 root root     3394 svi   3 22:51 CREDITS.md
drwxr-xr-x 2 root root     4096 svi   3 23:06 docs
drwxr-xr-x 2 root root     4096 svi   3 23:06 game
-rw-r--r-- 1 root root    23081 svi   3 22:51 known-bugs.txt
drwxr-xr-x 2 root root     4096 svi   3 23:06 lang
drwxr-xr-x 2 root root     4096 svi   3 23:06 lib
-rwxr-xr-x 1 root root 58587728 svi   3 23:06 openttd
-rw-r--r-- 1 root root     9758 svi   3 22:51 README.md
drwxr-xr-x 2 root root     4096 svi   3 23:06 scripts
drwxr-xr-x 5 root root     4096 svi   3 23:06 share

The game executable from that listing above is called openttd which runs the game (it has executable flag already set).

I attempted to create either symbolic or hard link to it on my desktop as follows:
Bash:
# Option 1, symbolic link
ln -s /opt/openttd-14.1-linux-generic-amd64/openttd ~/Desktop/openttd

# Options 2, hard link
ln /opt/openttd-14.1-linux-generic-amd64/openttd ~/Desktop/openttd

The link was created successfully with both methods separately but there are two problems:

1. When I run the link with double click on my Desktop it asks me if I want to execute it, choosing "Execute" does nothing
So first question is, how do I make the link executable so that it doesn't ask me to execute it but instead launch the game right away?

2. Why executing the link from Desktop does not launch the game and how do I launch it by executing the link on Desktop the same way as if I would run the executable from directory in /opt?

Otherwise executing the openttd executable from /opt directory works just fine.

Btw. I know I can create a Desktop file on my Desktop instead of a link and that works fine, but I want to understand why links don't work?
 


Some desktops do not allow you execute files owned by root, even if the files have execute permissions.
 
Some desktops do not allow you execute files owned by root, even if the files have execute permissions.
Thank you for response:

Bash:
sudo chown user:user -R /opt/openttd-14.1-linux-generic-amd64/
ln -s /opt/openttd-14.1-linux-generic-amd64/openttd ~/Desktop/openttd

Did not fix the issue :(
 
[Desktop Entry]
Name=Your Application Name
Exec=path/to/the/executable %F
Icon=path/to/the/icon
Type=Application
Comment=Short description of your application.
Categories=This name helps the system to organize the application.
MimeType=Which file the application can open, e.g: text/plain

Fill the above appropriately and save them inside the file:

sudo /usr/share/applications/YourAppName.desktop

reboot
 
I downloaded that game and did the exact same thing as you. When I use the full path(/opt/openttd-14.1-linux-generic-amd64/openttd) it runs.
pwd
/var/home/maarten/Desktop
./openttd Error: No available language packs (invalid versions?)
When I run it using the symlink from the desktop I get that message. When I then check game location I see a "lang" directory: /opt/openttd-14.1-linux-generic-amd64/lang

My guess for some reason it's not picking up the needed languages in that directory when running via a symlink from the desktop and then fails to start.
 
Last edited:
I downloaded that game and did the exact same thing as you. When I use the full path(/opt/openttd-14.1-linux-generic-amd64/openttd) it runs.

When I run it using the symlink from the desktop I get that message. When I then check game location I see a "lang" directory: /opt/openttd-14.1-linux-generic-amd64/lang

My guess for some reason it's not picking up the needed languages in that directory for and then fails to start.
I see! I've run:

Bash:
ln -s /opt/openttd-14.1-linux-generic-amd64/lang/ ~/Desktop/
This solves the error you mentioned, however it produces another error for missing music set, so my guess is that the executable needs to be run in it's installation directory (which is it's working directory perhaps).

According to man ln it's not possible to set working directory, unless I'm mistaken?
 
This solves the error you mentioned, however it produces another error for missing music set, so my guess is that the executable needs to be run in it's installation directory.
Here someone says.
where is the ottd binary? the lang files (along with everything else in the bin/bundle folder) should be with it, or at least in a place that can be found (see readme section 4.2)

also, compiling without any of those libraries will mean that the vast majority of newgrfs or savegames cannot be loaded
I found the manual installation guide and it expains how to setup a working desktop file.

The last line says.
Under the line that says, Exec=openttd add this line Path=/usr/share/openttd/ and save the file.
Try setting your custom path there, try it and see if it works?
 
Here someone says.
That explains why it doesn't work, thank you very much for finding this!

I found the manual installation guide and it expains how to setup a working desktop file.
Yes, I have it already set but was wondering why links don't work as I wanted them to, so they work but not in every scenario.
 
Yes, I have it already set but was wondering why links don't work as I wanted them to, so they work but not in every scenario.
I think the important part is that "Path" they mention in the desktop file. So I would think if you created a desktop file that looks something like this it would work.
Code:
[Desktop Entry]
Name=openttd
Exec=~/Desktop/openttd %F
Path=/opt/openttd-14.1-linux-generic-amd64
Type=Application
Yes, I have it already set but was wondering why links don't work as I wanted them to, so they work but not in every scenario.
Probably because the binary is compiled to search a certain path for the needed files to run, you would have to compile it from source yourself to customize that I would think.
 
I think the important part is that "Path" they mention in the desktop file. So I would think if you created a desktop file that looks something like this it would work.
Code:
[Desktop Entry]
Name=openttd
Exec=~/Desktop/openttd %F
Path=/opt/openttd-14.1-linux-generic-amd64
Type=Application

Probably because the binary is compiled to search a certain path for the needed files to run, you would have to compile from source yourself to customize that I would think.
Yes agree, but if there is desktop file then there's no need for link.

Here is my template for desktop file I used to create menu entry for OpenTTD,
comments taken from desktop file specification:

INI:
[Desktop Entry]
# 3 types of desktop entries: Application, Link and Directory
Type=Application
# Specific name of the application
Name=program
# Generic name of the application
GenericName=
# Path to an executable file on disk used to determine if the program is actually installed
TryExec=
# Program to execute, possibly with arguments
Exec=/opt/program
# If entry is of type Application, the working directory to run the program in.
TryExec=
# Icon to display in file manager, menus, etc
Icon=/opt/path/to/program.png
# Tooltip for the entry
Comment=Program Comment
# Categories in which the entry should be shown in a menu
Categories=Game
# A list of strings which may be used in addition to other metadata to describe this entry
Keywords=keyword
# Whether the program runs in a terminal window
Terminal=false
# This application exists, but don't display it in the menus
NoDisplay=false
# If true, the application has a single main window, and does not support having an additional one opened
SingleMainWindow=true
 
Yes agree, but if there is desktop file then there's no need for link.
Symlink isn't going to work for the previously stated reasons ;) and as it was verified in that OpenTTD forum link I shared.
Probably because the binary is compiled to search a certain path for the needed files to run, you would have to compile it from source yourself to customize that I would think.
Here is my template for desktop file I used to create menu entry for OpenTTD,
comments taken from desktop file specification:
You are missing the "Path" definition in there? Step 7 in the Linux manual Installation guide for OpenTTD?
Under the line that says, Exec=openttd add this line Path=/usr/share/openttd/ and save the file.
Code:
Path=/opt/openttd-14.1-linux-generic-amd64
 
Symlink isn't going to work for the previously stated reasons ;) and as it was verified in that OpenTTD forum link I shared.


You are missing the "Path" definition in there? Step 7 in the Linux manual Installation guide for OpenTTD?

Code:
Path=/opt/openttd-14.1-linux-generic-amd64
You are missing the "Path" setting in there?
Code:
Path=/opt/openttd-14.1-linux-generic-amd64
That's strange, yes I'm missing Path key but my current desktop file does not have it and the game runs fine from that desktop file.
I suppose the default working directory is already the same as directory where executable is located in, and the Path entry is used only if you want to change that default behavior.

According to specs, this key is also optional:

 
That's strange, yes I'm missing Path key but my current desktop file does not have and the game runs fine from that desktop file.
I left something out, but what I meant to say was try creating that symlink again. Point "Exec=" to that symlink(or whatever the location of your symlink is) and then "Path=" to Path=/opt/openttd-14.1-linux-generic-amd64 and then see if your symlink works then when being called from your desktop file?
 
I left something out, but what I meant to say was try creating that symlink again. Point "Exec=" to that symlink(or whatever the location of your symlink is) and then "Path=" to Path=/opt/openttd-14.1-linux-generic-amd64 and then see if your symlink works then.
Symlink isn't going to work for the previously stated reasons and as it was verified in that OpenTTD forum link I shared.
I'm not sure I understand, this sounds like I'd need to create both the desktop file and symlink?

I find this counterproductive because my goal was to avoid desktop file completely and use symlink only, but symlink only doesn't work with that game.
 
I'm not sure I understand, this sounds like I'd need to create both the desktop file and symlink?
Yes

I find this counterproductive because my goal was to avoid desktop file completely and use symlink only, but symlink only doesn't work with that game.
Yes it's counter-productive but it was just to test if the symlink works when creating a "Exec" definition pointing to the symlink together with the "Path=" definition. That way you can have your question answered if the symlink does work when the needed path is provided when launching.
 
@GatorsFan
Thank for your reply but I said in my OP I know this method.
The question is why links don't work and how to make them work?
@CaffeineAddict :-

Much depends on how your distro is set-up. I can drag executable items onto Puppy's desktop, and clicking on them will launch them just fine, without asking other permissions first. This comes down to two things, of course:-

  • Puppy runs AS root, by default

  • Puppy's 'desktop' is NOT a true 'desktop environment' in the way that most users will understand it. It's created through a combination of the JWM window manager AND the pinboard 'extension' of the ROX-filer file manager.....which permits the creation of a grid that is linked-to the FM yet at the same time operates independently of it.

I've been using our Pup for over 10 years, and I still don't fully understand it!

The upshot is that clicking on any linked executable on the 'pinboard' acts exactly as though you were launching by a click inside a file manager window.....because it still IS an integral, yet 'extended' part OF the file manager.

Don't try to figure it out. Take my advice and just accept it; it hurts your head to try and work out the mechanics of it!

~~~~~~~~~~~~~~~~~~~​

You'll find many Linux applications are built to be self-contained, and run entirely from within their own directory. There's a simple trick to 'fooling' the application into thinking that its own directory IS the user's $HOME directory.....and this then lets you write a wee launch script, inside that directory, pointing to its own executable.

Code:
HERE="$(dirname "$(readlink -f "$0")")"

Write this up the top of the script, usually just after the "#!/bin/sh/" line at the very start of any Bash script. You then treat the launch script as the 'executable', and can link this instead. Thus, the application thinks it's always being started from within its own directory.....and usually behaves itself.

Example; if you have an executable in that directory called "foo", you would write the launcher's exec line as follows:-

Code:
"$HERE/foo" "$@"

Curiously enough, if we use the "Path=" argument here in Puppyland, not only will our applications not show in the menu, they won't even launch. The same goes for the "%F" argument on the .desktop file's exec line....

The minimal set we use is as follows:-

[Desktop Entry]
Encoding
=UTF-8
Name=Application name to show in Menu
Comment=Short description
Exec=/path/to/your/executable
Icon=/path/to/your/icon
Type=normally Application, occasionally URL
Terminal=(usually 'false')
Categories=for organization
Mime-type=(sometimes, but not always)

This is all that's really needed for a .desktop entry to show AND function......all perfectly in accord with the freedesktop.org standards.


Mike. ;)
 
Last edited:
Yes it's counter-productive but it was just to test if the symlink works when creating a "Exec" definition pointing to the symlink together with the "Path=" definition. That way you can have your question answered if the symlink does work when the needed path is provided when launching.
I'm pretty sure what you suggest will work just fine because that's the default already because Path key is used if we want change working directory to something else instead.

---

And I have tested your suggestion, my desktop file is now this as you said:

INI:
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Name=openttd
Exec=/home/user/Desktop/openttd
Path=/opt/openttd-14.1-linux-generic-amd64
Icon=/opt/openttd-14.1-linux-generic-amd64/share/icons/hicolor/64x64/apps/openttd.png
Comment=A simulation game based upon Transport Tycoon Deluxe

Categories=Game
Keywords=openttd

Terminal=false
NoDisplay=false
SingleMainWindow=true

And that works! Exec entry is symlink.

Much depends on how your distro is set-up. I can drag executable items onto Puppy's desktop, and clicking on them will launch them just fine, without asking other permissions first. This comes down to two things, of course:-

Puppy runs AS root, by default
I understand, my desktop does not run as root by default, but @f33dm3bits 's suggestion works without asking me for permissions despite the game being owned by root and me running as standard user.
 

Members online


Latest posts

Top