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

5

35

I often see the terms "binary" and "executable" seemingly used interchangeably. Isn't it two terms to describe the same thing; the executable output program after a compilation process, that I can run on the terminal?

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


I have read the question and answers of What's the difference between binary and executable files mentioned in ndisasm's manual?. However, 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?
Tousle answered 20/1, 2020 at 15:22 Comment(4)
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.Grouchy
@Grouchy So, the output of a program or a script is ever an executable but not need to be always a binary?Tousle
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.Rie
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).Cissie
V
49

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.

Variolous answered 20/1, 2020 at 15:32 Comment(0)
B
5

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.

Burnham answered 20/1, 2020 at 15:39 Comment(2)
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.Variolous
@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.Burnham
B
3

This is one of those quirks of computing that stopped making sense a long time ago, but by then was cemented in tech lingo.

Compiled languages have always had a textual, human-readable, non-executable form, which is compiled into a binary, non-human-readable, executable form.

Before interpreted languages were widespread, and before binary media file formats were in routine use, it's understandable why "binary" would become shorthand for "binary executable compiler output", and why directories containing these files were called "bin".

Further, it's understandable why executable textual files like shell or python scripts—especially if they live in a bin folder—would sometimes be referred to as "binaries".

TL;DR: "binary" can mean "not a text file" or "executable file" or both. You have to use context clues to sort through the mess.

Bolter answered 22/6, 2023 at 18:0 Comment(0)
A
1

It depends on the definition. All files contain binary code and a "working" definition is the following:

  • Binary or text files

    • Files's binary code encodes text: text file

    • Files's binary code does not encode text: binary file

  • Executable or non-executable files

    • File can be executed: executable file

    • File can not be executed: non-executable file

Therefore the binary and executable are orthogonal properties i.e. any file can either have them or not in an independedent way. Some examples:

  • Binary executable: The .exe files in Windows, .app in MacOS (not a single file but a bundle) etc.
  • Text executable: Python scripts, bash scripts (require the corresponding interprenters) etc
  • Binary non-executable: PDF files, audio files etc
  • Text non-executable: C++ source code, a markdown file etc
Annice answered 27/10, 2022 at 12:59 Comment(0)
S
0

From my understanding binaries are machine readable format. Executables are also binaries but they are based on particular programs and are generally created by compiling the program.

Schuss answered 29/7, 2024 at 9:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.