简体   繁体   English

终端不会使用更新的 a.out,我该如何解决?

[英]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.

相关问题 没有./a.out命令如何执行程序? - How do I execute my program without ./a.out command? 为什么有些编译器使用“a.out”作为可执行文件的默认名称? - Why do some compilers use “a.out” as the default name for executables? 当用户键入./a.out -n时,我怎么知道n(正整数)是什么? - how do I know what n(positive integer) is when user types ./a.out -n? 如何获取.out 文件? - how to get a.out file? 无法通过Android终端运行.out文件 - Impossible to run a.out file through Android terminal 当我运行 a.out 时,代码会出现分段错误,在 linux 终端中使用 C,访问具有适当权限的文件 - Code gives a segmentation fault when I run a.out, using C in a linux terminal, accessing files that were given proper permissions 我如何在不使用 out 扩展名的情况下提供命令行参数,而不是 ./a.out 3 4 而是像 ./a 3 4 - How can i give command line arguments without using out extension ,not ./a.out 3 4 but like ./a 3 4 如何将./a.out的结果存储到文本文件中 - how to store results of ./a.out to a text file 如何使用exec()命令运行a.out - How to Run a.out Using exec() Command 给定一个完全链接的定义符号foo的a.out,如何在不重新链接a.out的情况下知道该定义来自哪个目标文件? - Given a fully linked a.out, which defines symbol foo, how can I tell which object file that definition came from, without relinking the a.out?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM