What are .dlls doing in Linux programs?
Games that were made with Unity3D for Linux contains .dll
files in their data folder GameDataFolder/Managed
.
Which is weird because I thought that Linux uses .so
files instead of .dll
files.
(The same is true for Android-Unity3D apps too.)
Why?
The games you are speaking about are based on the .NET Framework and running with Mono, which is a free and open-source implementation of Microsoft's .NET Framework.
Because these applications are .NET based, Assemblies have .dll extension. So you can see DLL files in the folders.
One .NET program designed for cross-platform use can run on Windows, Linux or Mac, with the same "binaries" (including DLLs which are also assemblies), which are compiled in MSIL and need a .NET/Mono runtime to be executed.
Please note that you also have some free applications (not only games) based on Mono Framework available in Ubuntu repositories. For example: Tomboy.
The .dll
files in GameDataFolder/Managed
belong to a native code program that uses Mono internally.
The Unity game engine embeds Mono (even on most Windows platforms).
Cross-platform executables and shared libraries that can be run either by the .NET Common Language Runtime or Mono are often named with .exe
and .dll
suffixes, respectively, even when they are not specific to Windows. When you find a .dll
file in a program for a GNU/Linux system like Ubuntu, or for any OS but Windows, this is usually why. Most of the time you find a .dll
in an Ubuntu system, Golboth's answer explains it. But that's not quite what's going on here.
The Unity game engine--which should not be confused with the default graphical interface in most Ubuntu releases--is a popular proprietary cross-platform game engine. This engine does not run on top of the .NET Framework or Mono. Instead, it embeds Mono, which is to say that Mono runs on top of it. This is how developers write whatever code their game needs that is not already part of the Unity engine.
In general, Mono may be used the same way Microsoft's .NET CLR is usually used, to run complete .NET/Mono programs. But Mono is also designed to be easily embeddable in native code applications, including to enable those applications to be customized. That's what's going on in the situation you are describing. The files you're seeing do not belong to a program that runs directly on top of Mono or the .NET CLR. Instead they belong to a native-code program that embeds Mono.
How the Unity Game Engine Uses Mono
The Unity game engine, which is written mostly in C++, hosts its own instance of Mono, which does not use--and may be different from--the version (if any) installed through your system's package manager. This embedded Mono runtime cannot be used to run standalone .NET/Mono programs, because that is not its purpose. Instead, the native code portion of the engine uses it to run CIL code. (CIL is Common Intermediate Language, which is its official name. It was previously called MSIL or Microsoft Intermediate Language, since Microsoft developed it originally.) Programmers making games that use the Unity engine usually write their own code in C#, though some other languages are supported.
The Unity engine embeds Mono even in Windows. For Universal Windows Platform games--and no other platforms--it uses the Microsoft .NET Framework instead of Mono. But the majority of Unity games on most platforms, including most mobile devices and gaming consoles, and including Ubuntu and Windows, use Mono. On some platforms IL2CPP is available as an alternative to Mono, and on a few only IL2CPP is supported. See Scripting restrictions for details.
Other Situations Where You May See .dll
Files On Ubuntu
Two situations where you are likely to see a .dll
file on Ubuntu have been described:
- A shared library that is intended to be used by a .NET/Mono application. Golboth's answer describes this in detail. This is what most
.dll
s you'll see on an Ubuntu system are. It just does not happen to be what the.dll
files in yourGameDataFolder/Managed
folder are for. - A file providing code that is used by an embedded Mono runtime to provide "scripting" for a native code application. That's what's going on in this case.
There are two other reasonably common cases where you may see a .dll
file on Ubuntu:
- The compiler for .NET Core produces
.dll
files rather than.exe
files, even when what you are compiling is not a library. The .NET Core runtime (called CoreCLR), and not the regular .NET Framework or Mono, runs these files. .NET Core is a Microsoft product, but unlike the standard .NET Framework, .NET Core is cross-platform with official support for GNU/Linux systems like Ubuntu, and it is free open source software. - Sometimes a
.dll
file you see on Ubuntu will just be a Windows library. You may see this if the program is being stored an Ubuntu system but run on Windows, or if you mount a Windows drive in Ubuntu. You may also see it in connection with programs that are able to be run on Ubuntu using Wine, including software that comes with Wine or that you install automatically withwinetricks
to support other Windows software.
This is not an attempt to exhaustively list all the circumstances where you may encounter a .dll
on Ubuntu. (For example, it could also be an OS/2 library.) However, I believe those four cases are the most common ones.