无法通过cmd运行C程序 [英] Unable to run C program through cmd

查看:311
本文介绍了无法通过cmd运行C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在学习C,并且正在尝试弄清楚如何通过命令控制台cmd运行它。我与Mingw一起安装了eclipse,并将它们添加到路径中:

Hello everyone I'm learning C and am trying to figure out how to run it through the command console cmd. I have eclipse installed along with Mingw and added these to the path:

C:\MinGW\bin\; C:\MinGW\msys\ 1.0\bin

C:\MinGW\bin\;C:\MinGW\msys\1.0\bin

我在notepad ++上编写了该程序,以便进行快速测试,并将其保存到C:\test.c以及文件夹C:\下在我试图弄清楚它时,用户是皮卡丘音乐的C代码:

I wrote this program on notepad++ for a quick test run and save it to C:\test.c and also under a folder C:\Users\Pikachu\Music\C code while I was trying to figure it out:

#include <stdio.h>

int main()
{
    printf("Hey, Buddy!\n");
    return 0;
}

在cmd控制台上,我键入:

On the cmd console I typed:

c:\>gcc test.c 

并收到错误消息:

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/id.exe: cannot ope
n output file a.exe: Invalid argument
collect2.exe: error: ld returned 1 exit status

当我输入时:

c:\>cd c:\Users\Pikachu\Music\c code

然后:

gcc test.c

gcc test.c

跳过一行,好像什么都没发生,然后回到第一个方框:

it just skipped a line as if nothing happened and went back to square one:

c:\Users\Pikachu\Music\c code>gcc test.c

c:\Users\Pikachu\Music\c code>

我想知道是否有人知道发生了什么并且可以帮助我,我会很高兴如果我可以从cmd看到嘿,好友!有人知道我为什么从c:\运行它会收到错误消息,而从Music\c code\test.c文件夹运行时却什么也没收到,即使我正在运行相同的文件test.c吗?

I was wondering if anyone knows what's going on and could help me out, I'd be so happy if I could see "Hey, Buddy" from cmd! Does anyone also know why I get the error message running it from c:\ and nothing when I run it from the Music\c code\test.c folder even though I'm supposedly running the same file test.c?

我尝试过搜索,并获得了有关计算机无法链接到正确dll的参考,但是我不确定如何将其实现到我的计算机上

I've tried searching around and have picked up references on how the computer can't link to the proper dll's however I'm not sure how to implement this to my specific problem.

哦,当我尝试在c中保存另一个文件时,很奇怪:\我收到一条消息,说我什至没有权限去做尽管5分钟之前我已经做到了。

Oh and curiously enough when I tried to save another file in c:\ I got a message saying that I didn't have permission to do that even though 5 minutes prior I had done just this. Any insights?

感谢您的帮助!

推荐答案

在您的C源文件中运行 gcc ,它将执行所有操作以生成一个可执行文件。我相信默认情况下它称为 a.exe ,但我建议使用 -o 选项将其命名:

When you run gcc on your C source file, all that it will do it generate an executable file. I believe its called a.exe by default but I would recommend naming it with the -o option:

gcc text.c -o test.exe

文件编译成功后,运行可执行文件向世界打招呼:

Once your file is successfully compiled, run the executable to say hello to the worls:

c:\Users\Pikachu\Music\c code> .\test.exe






至于第一个错误,可能与gcc无法在根 c:文件夹上创建输出可执行文件有关。因此,建议您对用户拥有的某个文件夹而不是系统文件夹进行编码。


As for the first error you got, maybe it has to do with gcc not being able to create the output executable on the root c: folder. I would recommend doing your coding some folder your user owns instead of on a system folder for this reason.

,gcc支持许多其他选项。我强烈建议使用 -Wall 打开警告并选择要遵循的C标准版本( -std = c99 -ansi ,以及标志)。

By the way, gcc supports many other options. I highly recommend using -Wall to turn on warnings and choosing what version of the C standard to follow (-std=c99 or -ansi, together with the -pedantic flag).

这篇关于无法通过cmd运行C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆