8

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

3 Answers3

23

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tim
  • 59,527
  • 19
  • 156
  • 165
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sth
  • 222,467
  • 53
  • 283
  • 367
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
EightyEight
  • 3,430
  • 4
  • 36
  • 67