Search code examples
ccompilation

Is there a Linux C compiler that doesn't name the output a.out?


I find a.out to be a tedious name for a file, and I am not interested in either the -o flag to rename output or any makefile when my build process is currently as clean as flex tfm.l; gcc lex.tfm.c.

Microsoft's cl compiler makes lex.tfm.exe by default. I know .exe wouldn't be applied on Linux, but is there any compiler that has similarly dropped this antiquated a.out? Or a pragma that would push the output name?


Solution

  • The Posix standard requires that the default executable filename be a.out. I think any reputable C compiler designed to run on a Unix(-like) operating system will respect that standard, even if it offends the aesthetic sensibilities of some users, so you're unlikely to find the compiler you are looking for.

    However, if it is that simple to build your executable, you can use make without creating a makefile:

    $ # No makefile:
    $ ls
    tfm.l
    $ # Default build recipe:
    $ make tfm
    lex  -t tfm.l > tfm.c
    cc    -c -o tfm.o tfm.c
    cc   tfm.o   -o tfm
    rm tfm.o tfm.c
    $ # Executable created with name 'tfm'
    $ ls
    tfm  tfm.l
    

    Not that I'd necessarily recommend doing that, but it is convenient for quick compiles. I prefer to add warning options to the compile line, so the startup script for my real shell sessions exports appropriate definitions of CFLAGS and some environment variables used by make.