To clarify, this is a question about binary Linux executables, not scripts, which can also be executable and also often lack an extension.
In my experience, most Linux binary executables lack a file extension; e.g. most of the files in the /bin
directory on Linux systems lack an extension.
On the other hand, most of the files in the /lib
directory have .so
in their file extension, and also have executable permissions. Trying to execute an .so
file directly usually results in seg fault or some error, which makes sense because shared libraries are usually intended to be dynamically linked. But as I understand it, if the .so
file has a main()
entrypoint, then you can run it as an executable as you would a normal executable (i.e. a file without an extension).
My questions:
- What is the difference between a shared library (
.so
extension) and an executable file ([none]
extension)? Is it just whether amain()
entrypoint is defined? - In C++, is there any difference (i.e. flags passed to the compiler) in compiling code into a shared library (
.so
extension) and compiling code into a Linux executable ([none]
extension).
Edit: This question talks about how to build an .so file using gcc command line, but doesn't identify the differences between building an .so versus a normal executable.