在 Linux 终端中执行 C 程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9290819/
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-08-06 04:35:20  来源:igfitidea点击:

Executing C program in Linux Terminal

clinuxterminal

提问by Rafi Kamal

I have compiled a program from my Ububtu 10.10 terminal by

我已经从我的 Ububtu 10.10 终端编译了一个程序

gcc file_name.c -o new_file

gcc file_name.c -o new_file

command. It compiled successfully creating an executable file named new_file. But when I was trying to execute it by this command

命令。它编译成功,创建了一个名为 new_file 的可执行文件。但是当我试图通过这个命令执行它时

./new_file

It says that permission is denied of new_file. I've checked the permission properties of that file found that I've permission to read & write it (I'm the only user of that system). Can you please help me to figure out the problem?

它说 new_file 的权限被拒绝。我检查了该文件的权限属性,发现我有权读写它(我是该系统的唯一用户)。你能帮我找出问题所在吗?

采纳答案by DonCallisto

You have to give it exe. permissions.

你必须给它exe。权限。

So: chmod +x new_file

所以: chmod +x new_file

When you create a new file with your gcc, by default, this isn't executable. So, you have to gave it permissions of execution.

当您使用 gcc 创建新文件时,默认情况下,这是不可执行的。所以,你必须给它执行权限。

With chmod(see this)you change permissions on file.

使用chmod(see this)您可以更改文件的权限。

In that specific case, you gave execution permissions ( + [plus] means gave, 'x' means execution ) to that file.

在这种特定情况下,您授予了该文件的执行权限( + [plus] 表示给予,'x' 表示执行)。

If you want to revoke that permission, you can type: chmod -x filename

如果要撤销该权限,可以键入: chmod -x filename

回答by Prabhavith

After compiling, the file is placed in a.outTry to use a.out.

编译后,文件放在a.outTry to use 中a.out