C语言 运行C程序时权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18446693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:16:39  来源:igfitidea点击:

Permission denied when running C program

c

提问by eden

I am trying to run this basic file (ex1.c) with zsh

我正在尝试使用 zsh 运行这个基本文件(ex1.c)

#include <stdio.h>
int main(int argc, char *argv[])
{
    puts("hello world.");

    return 0;
}

I am getting this error:

我收到此错误:

zsh: permission denied: ./ex1.c

回答by Matt Bryant

You need to compile it first, probably by doing gcc -o ex1 ex1.c.
After compiling it, you will have an executable called ex1, which you can run by doing ./ex1. If you receive another permission deniederror, you can make it executable by doing chmod +x ex1.

您需要先编译它,可能是通过执行gcc -o ex1 ex1.c.
编译后,您将拥有一个名为 的可执行文件ex1,您可以通过执行./ex1. 如果您收到另一个permission denied错误,您可以通过执行chmod +x ex1.

回答by viraptor

You can't just run a file with C code. You'll have to first compile it. If you have a gcccompiler available, that's going to be:

你不能只用 C 代码运行一个文件。你必须先编译它。如果你有一个gcc可用的编译器,那就是:

gcc -o ex1 ex.c
./ex1

回答by aragaer

It's a C source file, it is not supposed to be run like this, you have to compile it first.

这是一个C源文件,不应该这样运行,你必须先编译它。

This would do:

这会做:

make ex1 # Implicit rule which in turn will perform cc -o ex1 ex1.c
./ex1