使用 GCC 构建 Linux 可执行文件
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要创建名为
myprog
的可执行文件,您可以像这样调用 gcc:您也可以将 gcc 生成的 *.out 文件重命名为所需的名称姓名。
To create an executable called
myprog
, you can call gcc like this:You could also just rename the *.out file gcc generates to the desired name.
这就是可执行文件。 如果您不喜欢 a.out,可以将 -o 标志传递给编译器。 如果可执行文件未标记可执行位,您需要自己这样做:
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:
该可执行文件是“Linux 可执行文件”——也就是说,它可以在任何最新的 Linux 系统上执行。 您可以将文件重命名为您想要使用的名称
,或者更好的是,使用告诉 GCC 将其输出文件放在哪里
请记住,在 Linux 系统允许您运行该文件之前,您可能需要设置其“可执行位”:
另请记住在 Linux 上,文件的扩展名与它的实际内容关系不大 - 您的可执行文件可以命名为
something
、something.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
or better yet, tell GCC where to put its output file using
Keep in mind that before Linux systems will let you run the file, you may need to set its "executable bit":
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 evensomething.exe
, and as long as it's produced by GCC and you dochmod +x
on the file, you can run it as a Linux executable.