[英]Terminal will not use updated a.out, how do I fix that?
I'm compiling a C file on Terminal on my mac, but when I run the a.out file, it will only compile an old version of my file.我正在 Mac 上的终端上编译 C 文件,但是当我运行 a.out 文件时,它只会编译我的文件的旧版本。
For example, let's say my C file is made to print out "Hello, World!", I compile it using gcc and I run the a.out file, the a.out file will print out "Hello, World!".例如,假设我的 C 文件用于打印“Hello, World!”,我使用 gcc 编译它并运行 a.out 文件,a.out 文件将打印出“Hello, World!”。
If I then change the C file to print out "Goodbye", compile it and then run the a.out file, the Terminal will still print out "Hello, World".如果我随后更改 C 文件以打印出“Goodbye”,编译它然后运行 a.out 文件,终端仍将打印出“Hello, World”。 Does anyone know how to fix this?有谁知道如何解决这一问题?
All I am typing into the Terminal is我在终端中输入的只是
gcc main.c
~/a.out
Which is all I should be inputting right?我应该正确输入哪一个?
Please let me know if I didn't make anything clear enough.如果我说的不够清楚,请告诉我。 Thanks!谢谢!
You are typing in您正在输入
~/a.out
Which means "run the a.out
program from the home directory."这意味着“从主目录运行a.out
程序”。 I think you want to type我想你想打字
./a.out
Which means "run the a.out
program from the current directory."这意味着“从当前目录运行a.out
程序”。 If you are using gcc
, the newly-created program will be placed into the current directory (which, unless you're in the home directory, is not the same place), so the new version will run the right program.如果您使用gcc
,新创建的程序将被放置在当前目录中(除非您在主目录中,否则该目录不是同一个位置),因此新版本将运行正确的程序。
Hope this helps!希望这可以帮助!
gcc main.c
~/a.out
The first line will compile to a.out in your current directory, while the second line executes a.out from your HOME directory.第一行将编译为当前目录中的 a.out,而第二行从 HOME 目录中执行 a.out。 Are you in your home directory?你在你的主目录中吗?
If not, change the second line to如果没有,请将第二行更改为
./a.out
.
means current directory.表示当前目录。 So ./a.out
means execute the a.out
file in my current directory.所以./a.out
意味着执行我当前目录中的a.out
文件。
With ~/a.out
you run a binary from your home directory (see echo "$HOME"
), which may be not the one where you're compiling your new main.c
.使用~/a.out
您可以从主目录运行二进制文件(请参阅echo "$HOME"
),这可能不是您编译新main.c
。
Try this: ./a.out
(run from your current directory).试试这个: ./a.out
(从当前目录运行)。
You should use你应该使用
gcc main.c
./a.out
Notice the .
请注意.
(current directory) rather than ~
(home directory). (当前目录)而不是~
(主目录)。 The gcc
command will write a.out to the current directory when it compiles the code, which is not necessarily the home directory. gcc
命令在编译代码时会将 a.out 写入当前目录,该目录不一定是主目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.