Where is the difference between "binaries" and "executables" in the context of an executable program?

13,337

Solution 1

An executable file is one which can be executed; you would run it on the commandline by writing the name of the file itself as the command. On Unix systems, the file's "executable" flag must also be set. On Windows, the file's extension must be one of a fixed set of executable file extensions, including .exe.

A binary file is simply one in a binary (i.e. non-text) format. The binary format means that the file's contents should not be transformed for platform-specific reasons (e.g. replacing newlines from \n to \r\n).

Binary files are not necessarily executable, for example a library compiled to .dll or .so form is a binary but not an executable. A Java program compiled to .class or .jar form is not an executable file, but might be run using the command java -jar program.jar rather than the command ./program.jar.

Executable files are not necessarily binary, for example a Python script in text form can be made executable on Unix systems by writing a shebang line #!/usr/bin/python3 and setting the file's executable flag.

Solution 2

It helps to understand the context of the term "binary" here. It originates from compilers, which take the (text-based) source code of a program and turn that source code into an excutable form which is binary, not text-based. Thus in the context of compilers, "text" and "source code" are equivalent, as are "binary" and "executable". Interpreters on the other hand do not make the distinction between source code and executable code.

Things definitely got more complex over time with intermediate representations, such as used by the Java JVM, .Net's CLI or Python bytecode.

Share:
13,337

Related videos on Youtube

RobertS supports Monica Cellio
Author by

RobertS supports Monica Cellio

If you wonder about the phrase of "supports Monica Cellio" inside of my profile name, I´ll link you to the StackExchange Meta posts from Monica Cellio here and here for further information. Robert Schulz, Student of C and C++. I think it is always beneficial to educate oneself and even to iterate topics is a great source of increasing already made knowledge. Some useful links, I like to have handy: ISO/IEC 9899:2011 (C11) draft in HTML format ISO/IEC 14882:2017 (C++17) draft in PDF format Minimal Reproducible Example SOCVR chat room Why should I always enable compiler warnings? Undefined, Unspecified and Implementation-defined Behavior in C and C++ The Definitive C Book Guide and List How do I use arrays in C++? Do I cast the result of malloc How does realloc() reallocate the memory? Why is “while ( !feof (file) )” always wrong? Why is the gets function so dangerous that it should not be used? scanf leaves the new line in the buffer Passing an array as an argument to a function in C C pointer notation compared to array notation: When passing to function How can I do GUI programming in C? What is the difference between char s[] and char *s? Curious C Stack Overflow Questions: How does this piece of code determine array size without using sizeof( )? With arrays, why is it the case that a[5] == 5[a]? Deleted: https://stackoverflow.com/questions/60465070/why-does-my-char-array-need-one-more-element-than-expected-to-store-a-string/ https://stackoverflow.com/a/60832504/12139179 https://stackoverflow.com/a/61069520/12139179

Updated on June 07, 2022

Comments

  • RobertS supports Monica Cellio
    RobertS supports Monica Cellio almost 2 years

    I often see the terms "binary" and "executable" seemingly used interchangeably for the same thing.

    Ain´t it two terms to describe the exact same thing; The executable output program after a compilation process, which I can run on the terminal?

    What do strengthen my assumption, that these two things shall be the same is also, that it is a common practice to provide a bin folder ("bin" as abbreviation for "binaries") inside the installation folders of an application, to store the executable files in, which users are be able to run.


    I have read the question and answers of What's the difference between binary and executable files mentioned in ndisasm's manual? but the question and their answer are more focused on the respective environments of Clang and ndisasm.

    I´ve also read the question and the answers of https://softwareengineering.stackexchange.com/questions/121224/what-are-binaries at the Software Engineering forum, but also here no distinction between an executable and a binary; only what the term of "binary" in general can refer to:

    But, in Computing, Binary refers to :

    • Binary file, composed of something other than human-readable text
    • Executable, a type of binary file that contains machine code for the computer to execute
    • Binary code, the digital representation of text and data

    [Source: https://softwareengineering.stackexchange.com/a/121235/349225]

    where, in the context of the output program of a compilation process, a binary was referred to as the same as an executable, as well as:

    The word binaries is used as a set of files which are produced after compiling essentially the object code that runs on machines. (and virtual machines/runtimes in case of Java/.NET)

    [Source: https://softwareengineering.stackexchange.com/a/121234/349225 ]

    where it was referred to the same.


    • What is the difference between "binaries" and "executables" in the context of an executable program?
    • Where is the distinction?
    • Ctx
      Ctx over 4 years
      binaries and executables are different sets with some overlap. A binary like ls is an executable. A perl script can also be an executable, but is no binary, and a mp3 file is a binary, but no executable.
    • RobertS supports Monica Cellio
      RobertS supports Monica Cellio over 4 years
      @Ctx So, the output of a program or a script is ever an executable but not need to be always a binary?
    • Guy Coder
      Guy Coder over 4 years
      I know this will confuse you more, but should also help you realize when a good answer has been given. See: MS-DOS exe2bin In other words, those of us who have been programming since the 1970's know the historical reasons.
    • aka.nice
      aka.nice over 4 years
      From computer POV, every file is binary. The most relevant distinction is text file vs non text (binary) file. Text files contains characters encoded in some well known binary format... Err, there are many possible encodings nowadays! ASCII CP1250 UTF8 UTF16... The distinction is in the eye of the beholder (hence contextual).
  • kaya3
    kaya3 over 4 years
    It's worth noting that even just for C++ specifically, a compiler's output isn't necessarily executable, for example a shared library can be compiled to a .dll or .so file. If we consider other languages than C++, then for example the Typescript compiler's output is Javascript code, which is text but not "source" code.
  • MSalters
    MSalters over 4 years
    @kaya3: Well, a .DLL is in the Portable Executable format (PE), so it's "executable" in some sense of the word. And to make things complex, GetBinaryType(filename) will check if a file is in PE format, but it returns returns FALSE (0) for a DLL. One of those cases where the name doesn't match the functionality.