【问题标题】:Termux permission deniedTermux 权限被拒绝
【发布时间】:2018-10-30 12:16:58
【问题描述】:

我想在 Termux(c++) 中执行一个简单的代码,但是每次我得到一个错误:

bash: ./test.cpp: Permission denied
Storage permission is on and gcc is installed. 

我需要root还是别的什么?

【问题讨论】:

  • 不能执行C++源文件,需要先编译链接,生成可执行文件。任何 C++ 介绍中都应该有说明。
  • 我面临着类似的问题ls -l test.sh; ./test.sh-rwxrwxrwx 1 root root 20 Nov 14 12:35 test sh bash: ./test.sh: Permission denied

标签: android c++ termux


【解决方案1】:

正如 molbdnilo 所说,你应该先编译你的源文件:

g++ test.cpp

然后执行生成的二进制文件(默认名称是a.out)

./a.out

【讨论】:

    【解决方案2】:

    在 termux 自己的目录中编译并运行它。 只需启动 termux:

    cd storage/ 
    nano test.cpp
    g++ test.cpp "./a.out" 
    

    你可以运行它!

    【讨论】:

      【解决方案3】:

      C++ 做不到,必须先编译。 如果是Python的话,可以在第一行加上#!/usr/bin/env python,在shell中运行chmod 744 xxx.py,再运行./xxx.py.xxx.py就可以运行了。

      【讨论】:

        【解决方案4】:

        我从来没有使用过termux,但想建议你编译以下几点

        • 使用chmod 777 test.cpp向所有用户授予读写和执行权限
        • 使用 g++ 和 gcc 编译 C++ 文件 使用sudo apt-get update 后跟sudo apt-get install g++
        • 使用g++ test.cpp -o test编译 并使用./test 执行该文件。 这就是它在 Linux 系统中的工作方式。

        【讨论】:

        • 在源文件上设置可执行位不是一个好主意。
        猜你喜欢
        • 1970-01-01
        • 2017-04-19
        • 2015-08-30
        • 1970-01-01
        • 2018-07-19
        • 2018-02-05
        • 2015-04-28
        相关资源
        最近更新 更多