What are .dlls doing in Linux programs?

12,251

Solution 1

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.

Solution 2

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:

  1. 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 .dlls you'll see on an Ubuntu system are. It just does not happen to be what the .dll files in your GameDataFolder/Managed folder are for.
  2. 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:

  1. 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.
  2. 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 with winetricks 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.

Share:
12,251
xuwenbuwer
Author by

xuwenbuwer

ooooooo

Updated on September 18, 2022

Comments

  • xuwenbuwer
    xuwenbuwer almost 2 years

    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?

  • Sanya_Zol
    Sanya_Zol almost 7 years
    Also note that those dll's aren't "real" windows dll's but actually compiled .NET bytecode.
  • code_dredd
    code_dredd almost 7 years
    Also note that file extensions, including .dll and .so, are meaningless in Linux. They're only used for our convenience.
  • FMaz
    FMaz almost 7 years
    @ray Can you explain? I thought they are still a standard to convey file type information, hence aren't meaningless?
  • hmakholm left over Monica
    hmakholm left over Monica almost 7 years
    @FynnMazurkiewicz: It's more a matter of slightly differing design traditions than a single central attribute that either system enforces. In fact, both the Windows kernel and the Linux dynamic linker will happily load a shared library (in their respective formats) no matter whether its filename ends in .dll or .so or something else. For historical reasons the LoadLibrary syscall in Windows will in some cases append ".dll" to the filename if it doesn't have an extension already, but that's not how it's typically used.
  • Iluvathar
    Iluvathar almost 7 years
    @ray not quite: gcc won't find a library supplied like e.g. -lm if its file name doesn't end with .so or .a or versioned variants thereof.
  • code_dredd
    code_dredd almost 7 years
    @Ruslan The man page for gcc's -l option suggests that what you point out is simply a convention, not b/c the extensions are actually necessary. "The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a ... [the] -l surrounds library with lib and .a and searches several directories."
  • code_dredd
    code_dredd almost 7 years
    @FynnMazurkiewicz They're meaningless to the OS. They certainly convey some visual information to us, since we would not be expected to understand magic bytes inside the file's metadata to determine if it's really a text file or an executable. Consider the built-in commands (e.g. ls, cat, etc.) None of them have file extensions to "mark" them as executable; it's the file permissions combined with the fact that they're programs that actually allows them to execute. You can rename an executable to have a .txt extension and still run it if it has the correct permissions set.
  • wizzwizz4
    wizzwizz4 almost 7 years
    @HenningMakholm If experience with other Windows programs is to be trusted, one can simply append a . to an extensionless DLL to make it load without it automatically appending .dll.
  • hmakholm left over Monica
    hmakholm left over Monica almost 7 years
    @wizzwizz4: Correct. That's documented, too.