BlueMonkMN's picture

OpenTK.dll.config and dllmap configuration

The OpenTK,dll.config seems to be working great. So why would I not be able to get the same thing to work for the main application? I have an application "tmp.exe" which I have both tried to compile under Windows with Visual Studio and compile with MonoDevelop under Linux. In both cases, the program comes up just fine and shows me pretty graphics (an indication that OpenTK is working great), but as soon as I try to start the phase where sound is involved, I get a DllNotFoundException stating that fmodex was not found. The same application runs fine under windows when fmodex.dll is present. But when when fmodex is not present, and libfmodex-4.22.01.so is present instead, I can't seem to get it to work. I have the following content in tmp.exe.config:

<configuration>
<dllmap os="linux" dll="fmodex.dll" target="libfmodex-4.22.01.so"/>
</configuration>


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Mono actually does that: if you don't specify a dll.config, it tries to map "fmodex" to "fmodex.dll" on Windows and "libfmodex.so" on Linux. Unfortunately, most libraries have extra decorations (e.g. opengl32.dll or libfmodex-4.22.01.so), which make the dll.config necessary.

BlueMonkMN's picture

Well, it's all working out great. I can now easily convert SGDK2 projects to Linux. Here's a Tetris game, in both compiled form and as an MDP project, both generated by SGDK2: MonoTetris.tar.gz

objarni's picture

BlueMonkMN: Could you write up an howto on what you learned from this? It would be really beneficial to me as a Ubuntu/Windows developer :)

BlueMonkMN's picture

You mean like this?

How To Map Windows DLLs to Linux Libraries When Running .NET Apps in Mono
In order for the same source code to compile and run in both Windows and Linux when the code includes P/Invoke calls to functions in external libraries, the system needs to know where to find compatible library code when running under Linux that corresponds to functions in referenced unmanaged Windows DLLs. In order to achieve this, Mono supports the use of <dllmap> entries in the config file for a DLL or application. The details of dllmap can be found at www.mono-project.com. This is an example of the content of a config file for an application that uses FmodEx:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <dllmap os="linux" dll="fmodex" target="./libfmodex-4.22.01.so"/>
</configuration>

The config file to re-map functions called by a DLL must be named the same as the DLL with a ".config" extension. For example, OpenTK.dll.config re-maps all the DLLs called by OpenTK. For an application, the filename is the application with a ".config" extensions. For example "TestApp.exe.config" will be the configuration file for TestApp.exe.

Take care when creating a project that includes config files. The .NET-based IDEs seem to have implicit behavior when it comes to config files. If you add a file named "app.config" to your project, Visual Studio will automatically copy that to the ourput folder when compiling the application and rename it as (for example) TestApp.exe.config even if the file is not set to be compiled or copied to the output folder. As far as I can tell, this is implicit/secret behavior of the environment. Take care that whatever environment you are using handles that and also that the config files for all dependent DLLs (such as OpenTK.dll.config) are also copied/moved along with the DLLs. If the config files are not copied automatically, you may have to, copy them another way. You may be able to add a DLL's config file to your project and set it to copy to the output folder because the DLL's config file is already named correctly (unlike app.config) and just needs to be copied.

Note that the process of compiling source code itself is at a level below the copying of config files. It's the IDE or environment that copies these, not the compiler. MSBuild (a solution builder included with the .NET framework 2.0+) will copy/generate the application config file, but csc and vbc (command line C# and VB.NET compilers included with the framework) will not, nor will the compilers in the CodeDOM portion of the .NET framework.

Another thing to be careful about is the location of the re-mapped libraries running under Mono. In my own development, I tend to prefer to keep the unmanaged libraries in the same directory as the application (because I deal with libraries that aren't commonly delivered with Windows or Linux) in order to encapsulate all the executable code for the application in one place. So I have used a "./" in front of the re-mapped library name so force Mono to find the library in the current directory where the application runs. Details of where Mono looks for dependencies is documented at www.mono-project.com

One final thing to be careful about. Windows and Mono will load libraries whether or not the ".dll" (and I assume ".so") extension is included in the name, but the dllmap entries are more picky. If your code requests "fmodex", but your config file refers to "fmodex.dll", Mono will look for fmodex when running in Linux instead if matching the dllmap entry to look for the remapped value.

If you have any additional information about how a config file for a DLL project gets generated from the source directory into the output directory, please comment here.

objarni's picture

Wow thanks x1000!! Hope this could be put somewhere appropriate in the OpenTK Book!

BlueMonkMN's picture

At least one person is reporting problems, but I'm not seeing them. I'd appreciate any other feedback/info people could give me while running tetris.exe from the following archive under Linux (MonoDevelop source code is included):
http://sgdk2.enigmadream.com/support/MonoTetris.tar.gz

In my own environment, I simply run tetris.exe by typing tetris.exe or double-clicking on it, and it works fine. In the problem environment a DLLNotFoundException is occurring.

What behavior do you see?

I am running mono version 1.2.6, x86 and MonoDevelop 1.0.

objarni's picture

I get this error under Ubuntu 9.04 with WinForms installed. See attached png.

AttachmentSize
TetrisError.png22.39 KB
the Fiddler's picture

It likes like you are missing FMOD.

BlueMonkMN's picture

The file "libfmodex-4.22.01.so" is included in the archive. That's FMOD.

Mincus's picture

I initially had the same problem as objarni.
Turns out the libfmodex included is 32-bit (I'm running 64-bit xubuntu 8.10) and Mono seems to throw a DLL not found exception when the native library pointed at is the wrong architecture.

So, wandered over to the FMOD website download page (http://www.fmod.org/index.php/download) and grabbed the latest version.

Resulted in: System.ApplicationException: FMOD error! ERR_OUTPUT_INIT - Error initializing output device.
Full error window is attached.
This might be because it's a different version of FMOD (I used the one immediately obvious on the download site -- 4.24.03).

AttachmentSize
tetriserror.jpg34.72 KB