使用 GCC 构建 Linux 可执行文件

发布于 2024-07-27 22:23:30 字数 248 浏览 2 评论 0原文

我正在使用 Ubuntu 8.10 (Intrepid Ibex) 并编译 C++使用 GCC 生成文件,但是当我编译时,gcc 会生成一个作为可执行文件的 a.out 文件。 如何制作 Linux 可执行文件?

I'm using Ubuntu 8.10 (Intrepid Ibex) and compiling C++ files with GCC, but when I compile, gcc makes an a.out file that is the executable. How can I make Linux executables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

樱花落人离去 2024-08-03 22:23:31

要创建名为 myprog 的可执行文件,您可以像这样调用 gcc

gcc -c -o myprog something.c

您也可以将 gcc 生成的 *.out 文件重命名为所需的名称姓名。

To create an executable called myprog, you can call gcc like this:

gcc -c -o myprog something.c

You could also just rename the *.out file gcc generates to the desired name.

弥繁 2024-08-03 22:23:31

这就是可执行文件。 如果您不喜欢 a.out,可以将 -o 标志传递给编译器。 如果可执行文件未标记可执行位,您需要自己这样做:

chmod u+x ./a.out
./a.out

That is the executable. If you don't like a.out, you can pass an -o flag to the compiler. If the executable isn't marked with an executable bit, you need to do so yourself:

chmod u+x ./a.out
./a.out
旧时光的容颜 2024-08-03 22:23:30

该可执行文件是“Linux 可执行文件”——也就是说,它可以在任何最新的 Linux 系统上执行。 您可以将文件重命名为您想要使用的名称

rename a.out your-executable-name

,或者更好的是,使用告诉 GCC 将其输出文件放在哪里

gcc -o your-executable-name your-source-file.c

请记住,在 Linux 系统允许您运行该文件之前,您可能需要设置其“可执行位”:

chmod +x your-executable-name

另请记住在 Linux 上,文件的扩展名与它的实际内容关系不大 - 您的可执行文件可以命名为 somethingsomething.out 甚至 some.exe,只要它是由 GCC 生成的,并且您对该文件执行 chmod +x 操作,就可以将其作为 Linux 可执行文件运行。

That executable is a "Linux executable" - that is, it's executable on any recent Linux system. You can rename the file to what you want using

rename a.out your-executable-name

or better yet, tell GCC where to put its output file using

gcc -o your-executable-name your-source-file.c

Keep in mind that before Linux systems will let you run the file, you may need to set its "executable bit":

chmod +x your-executable-name

Also remember that on Linux, the extension of the file has very little to do with what it actually is - your executable can be named something, something.out, or even something.exe, and as long as it's produced by GCC and you do chmod +x on the file, you can run it as a Linux executable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文