简体   繁体   English

无法在Raspbian(Debian)上使用Geany或Terminal运行C ++程序

[英]Can't run C++ program with Geany or Terminal on Raspbian (Debian)

(I'm not quite sure if this is the place to ask this, if need be please move to another Stack Exchange community - if possible) (我不太确定这是问这个地方的地方,如果需要的话,请移到另一个Stack Exchange社区-如果可能的话)

I am learning C++ on my Raspberry Pi (With Raspian (Debian), btw), and I have created a simple Hello World program with the Geany IDE. 我正在Raspberry Pi(使用Raspian(Debian),顺便说一句)上学习C ++,并且已经使用Geany IDE创建了一个简单的Hello World程序。 I compile, build the program, and then run it. 我编译,构建程序,然后运行它。 However, I get an error: 但是,我得到一个错误:

./geany_run_script.sh: 5: ./geany_run_script.sh: ./HelloWorld: Permission denied


------------------
(program exited with code: 126)
Press return to continue

The compile command is g++ -c "%f" and the build command being g++ -o "%e" "%f" . 编译命令为g++ -c "%f" ,构建命令为g++ -o "%e" "%f" If you find it helpful the file type is .cxx . 如果发现有帮助,则文件类型为.cxx

I would like to use Geany to run due to convenience. 由于方便,我想使用Geany来运行。 Unfortunately I can't run it with the Terminal as super user, even after using chmod +x . 不幸的是,即使使用chmod +x ,我也无法以超级用户身份在Terminal上运行它。

Your problem seems do not relates to Geany IDE. 您的问题似乎与Geany IDE无关。 So you need to change permissions on executed file. 因此,您需要更改执行文件的权限。 Please try the following command: chmod 777 your_filename 请尝试以下命令:chmod 777 your_filename

To run a file on Linux the user needs to have the x either on user or group. 要在Linux上运行文件,用户需要在用户或组上使用x This looks like ---x--x--x or in hex 0111 on POSIX file systems. 在POSIX文件系统上,它看起来像---x--x--x或十六进制0111。 So chmod +x should work on most systems using eg EXT[2|3|4] or XFS. 因此, chmod +x应该可以在大多数使用EXT [2 | 3 | 4]或XFS的系统上运行。 So your start was correct. 所以您的开始是正确的。 BTW: When compiling a C file via Geany, it's already set to be executable. 顺便说一句:通过Geany编译C文件时,它已经设置为可执行文件。

As you mention your USB stick is formatted with FAT32 which is not supporting the POSIX things here so chmod will not take any effect. 正如您提到的,您的USB记忆棒已格式化为FAT32,在此不支持POSIX,因此chmod不会起作用。 However, the file permissions are eg to execute something is based on the umask used for mounting. 但是,文件权限是例如根据用于挂载的umask执行某些操作。 On traditional Linux systems this can be configured in /etc/fstab . 在传统的Linux系统上,可以在/etc/fstab进行配置。 Using udev or something else, somewhere else it can be also configured (read: than it depends, what you are using to mount the stick) 使用udev或其他工具,也可以在其他地方进行配置(阅读:取决于安装挂载杆的方式)

In addition mount can set a device as noexec which pretty much is an good idea for devices as USB-sticks or unknown CD/DVD. 另外,mount可以将设备设置为noexec ,这对于USB记忆棒或未知CD / DVD的设备来说是个好主意。 However, if this flag is set during mounting, your files on that device can't be executed -- only read and write is permitted. 但是,如果在挂载期间设置了此标志,则无法在该设备上执行文件-仅允许读写。 Again this can be set on /etc/fstab or maybe somewhere else depending on what you might using in addition. 同样,这可以在/etc/fstab上设置,也可以在其他地方设置,具体取决于您可能还会使用什么。

To check this, run the mount command without and parameters. 要检查这一点,请运行不带和参数的mount命令。 It will give you a list where your USB device should be included. 它会为您提供一个清单,其中应包括您的USB设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM