Can't run executables from nautilus

守給你的承諾、 提交于 2019-12-23 05:17:59

问题


(the warning that shows up) On Ubuntu 18.04, I compiled a c++ sample which only included stdio.h and an empty main function using g++ test.cpp -o test .

No errors popped up and I had no issues running it from the terminal.

However, once I go on nautilus and try to run it by clicking on test, a warning pops up, asking me to pick a program to open the shared library.

How do I make sure the program is compiled as an executable/ is seen as an executable by the file manager?

Edit: stat output on the executable (recompiled and changed the name to asdff):

File: asdff
  Size: 10600       Blocks: 24         IO Block: 4096   regular file
Device: 808h/2056d  Inode: 4200517     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/  miguel)   Gid: ( 1000/  miguel)
Access: 2018-05-18 15:22:58.009993285 +0100
Modify: 2018-05-18 15:22:58.009993285 +0100
Change: 2018-05-18 15:22:58.009993285 +0100
Birth: -

df output on the same executable:


Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda8      128206036 102694048  18956444  85% /

desktop entry:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=asdff
Exec=./home/miguel/Desktop/asdff
Icon=/home/miguel/Desktop/index.png

回答1:


I notice that you were trying to use a desktop file. That is good.

Because Nautilus is patched to remove the ability to execute programs. It's a security problem.

Put your desktop file in the right location for the application launcher and open it that way instead of by using Nautilus. This location is $HOME/.local/share/applications, I believe.




回答2:


This answer assumes your test program lies on your home folder and that /home has its own partition, with the noexec option (this is the default on Ubuntu).

man mount says:

noexec Do not permit direct execution of any binaries on the mounted filesystem.

This means your system prevents you from running your test program on your home folder.

If this is true, you can either move your program outside of /home or change the way your home partition is mounted by editing your /etc/fstab file. See man fstab, but basically you want to add the exec option.


Other hypothesis:

  1. For whatever reason, your test program does not have an execute premission. Check that with $stat test.
  2. For whatever reason, the name you gave to your test program infer with the system's shell builtin command test. Rename your program.



回答3:


Run your program in a terminal emulator on the command line, using your interactive shell. Be aware of the PATH variable (you might change it by configuring your interactive shell, e.g. in ~/.bashrc). Your shell will use execve(2) (after globbing) to run your executable binary (so it should stay on some executable partition, as answered by YSC and be executable - see stat(2)). You want to see the stdout and stderr outputs of your program. See also this answer.

Use g++ with all warnings and debug info, so g++ -Wall -Wextra -g. Avoid naming test your program (that name conflicts with test(1)). If your executable uses other libraries, you might need to explicit some rpath at link time.

Only when your program is a GUI program (e.g. coded for a widget toolkit like Qt) should you care to (eventually) be able to run it in your desktop with a click (details could be specific to your desktop environment). You'll bother about that much later (and you probably even should not, and leave that burden to your user, or to the packager of your program).

I make sure the program [....] is seen as an executable by the file manager?

That is a sysadmin question and could depend upon your desktop environment or window manager. I won't bother at first, but later you might have some desktop entry specification (some file ending with .desktop) describing your program. So use an editor to create that asdff.desktop textual file (it probably should go into your $HOME/Desktop/ directory and should mention absolute file paths).

Exec=./home/miguel/Desktop/asdff

The . is a typo, should be Exec=/home/miguel/Desktop/asdff without any dot.

Every program on Linux is started by execve(2) (done by a shell, your desktop environment, or some other program). You should use a shell in a terminal emulator to start most of your programs, especially when developing them. And you certainly should expect your users to run your program with their shell (I hate starting programs with my mouse), perhaps in some shell script combining your program with other ones. Read also about the Unix philosophy.



来源:https://stackoverflow.com/questions/50412577/cant-run-executables-from-nautilus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!