10

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?

6
  • What is the difference for you between an executable and a Linux executable ?
    – Ben
    Jul 17, 2009 at 0:38
  • can you clarify? The *.out files are the executables. Do you need another type of executables?
    – notnoop
    Jul 17, 2009 at 0:39
  • Nathan, the 'a.out' name is a historical artifact, from the earliest Unix compilers. See the Wikipedia article on the subject: en.wikipedia.org/wiki/A.out
    – quark
    Jul 17, 2009 at 1:05
  • @notnoop: It's just a.out, not *.out. (Greetings from the future!) Apr 1, 2018 at 20:52
  • 1
    a.out should already be executable. No need to do anything else. Just run with ./a.out Jul 4, 2019 at 16:20

3 Answers 3

25

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.

4
  • 4
    Doesn't gcc (in fact the linker it calls) already set the executable bit in its output file?
    – CesarB
    Jul 17, 2009 at 0:58
  • 2
    @CesarB: Yes, the gcc call makes 'your-executable-name' executable by default.
    – quark
    Jul 17, 2009 at 1:04
  • 1
    Some systems might have a rename command, but mv is the usual way to rename a file. Apr 1, 2018 at 20:52
  • Conversely it may or may not set too much: -rwxrwxr-x. Apr 3, 2022 at 13:33
4

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.

3

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
3
  • The *.out file already is an executable, but how i can build a native Linux executable, linux native executables don't have extensions. Jul 17, 2009 at 0:40
  • 5
    In linux, extensions don't matter. You can just rename the file to anything you like.
    – notnoop
    Jul 17, 2009 at 0:41
  • When the problem is permition i know. Thanks! Jul 17, 2009 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.