Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono on OSX: Couldn't find gtksharpglue-2.dll

Tags:

c#

macos

mono

gtk

I'm trying to do my first steps in C# and wanted to build an empty GTK window as my first task. Via macports I installed the following packages:

I also use MonoDevelop from the Mono homepage.

I added gtk-sharp.dll (from /opt/local/lib/mono/gtk-sharp-2.0) to my references. My code looks like this:

using System;
using Gtk;

namespace lolbr_client
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine("Loading..");
            Window window = new Window("test");
        }
    }
}

When I compile and run that snippet, it seems to find and include the GTK-library, it prints "Loading.." to the console, but the line after Console.WriteLine() causes this error:

System.DllNotFoundException: gtksharpglue-2
  at (wrapper managed-to-native) Gtk.Container:gtksharp_gtk_container_get_focus_child_offset ()
  at Gtk.Container..cctor () [0x00000] in <filename unknown>:0

While that particular .dll doesn't exist on my filesystem, a quick locate gtksharpglue-2 revealed the following files:

/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgtksharpglue-2.so
/opt/local/lib/libgtksharpglue-2.a
/opt/local/lib/libgtksharpglue-2.la
/opt/local/lib/libgtksharpglue-2.so

Do those files help me? What are the next steps from here to debug/fix this? I already searched Google, but either I am too new to this subject to recognize useful information, or useful information just doesn't exist. Can someone help me? Thanks in advance!

like image 790
Fabian Avatar asked Dec 14 '12 19:12

Fabian


3 Answers

The solution how to run GTK Sharp MONO apps (compiled for example with Xamarin Studio) is to do following:

  1. Compile your mono/gtk-sharp app as Release

  2. Create shell script file (bash) like this (name it anyway you wish)

    [sharp]!/bin/sh
    
    export DYLD_FALLBACK_LIBRARY_PATH="/Library/Frameworks/Mono.framework/Versions/Current/lib:$DYLD_FALLBACK_LIBRARY_PATH:/usr/lib"    
    exec /Library/Frameworks/Mono.framework/Versions/Current/bin/mono ./AsketicExcel.exe
    

enter image description here

_3. Then you could run this form Terminal or you can use this packager tool http://sveinbjorn.org/platypus and create normal OSX App :) (include in the package all your files in Release dir)

Then in order to run this app on other mac you will need to install GTK# & Mono runtime http://www.go-mono.com/mono-downloads/download.html

In the end it would look like: enter image description here

like image 158
Evalds Urtans Avatar answered Sep 19 '22 05:09

Evalds Urtans


I have found the issue, my dllmap was incomplete.

I added the following lines to /Library/Frameworks/Mono.framework/Versions/2.10.9/etc/mono/config:

<dllmap os="osx" dll="libgtk-win32-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgtk-quartz-2.0.0.dylib" />
<dllmap os="osx" dll="glibsharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libglibsharpglue-2.so" />
<dllmap os="osx" dll="libgthread-2.0-0" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgthread-2.0.0.dylib" />
<dllmap os="osx" dll="libgthread-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgthread-2.0.0.dylib" />
<dllmap os="osx" dll="libglib-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libglib-2.0.0.dylib" />
<dllmap os="osx" dll="libgobject-2.0-0.dll" target="/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/libgobject-2.0.0.dylib" />
like image 37
Fabian Avatar answered Sep 20 '22 05:09

Fabian


Ran into this issue aswell and although Fabian's answer was on the right track, it wasn't the solution for me. As per this bug filed with Xamarin, the following entries to the dllmap were required to be added to /Library/Frameworks/Mono.framework/Versions/Current/etc/mono/config (with a couple of duplicates removed).

<dllmap os="osx" dll="glibsharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglibsharpglue-2.so" />
<dllmap os="osx" dll="gthread-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgthread-2.0.0.dylib" />
<dllmap os="osx" dll="gthread-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgthread-2.0.dylib" />
<dllmap os="osx" dll="glib-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglib-2.0.0.dylib" />
<dllmap os="osx" dll="glib-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglib-2.0.dylib" />
<dllmap os="osx" dll="glibsharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglibsharpglue-2.so" />
<dllmap os="osx" dll="gtksharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgtksharpglue-2.so" />
<dllmap os="osx" dll="gobject-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgobject-2.0.0.dylib" />
<dllmap os="osx" dll="gobject-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgobject-2.0.dylib" />
<dllmap os="osx" dll="gtk-quartz-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgtk-quartz-2.0.0.dylib" />
<dllmap os="osx" dll="gtk-quartz-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgtk-quartz-2.0.dylib" />
like image 29
AdrianCooney Avatar answered Sep 22 '22 05:09

AdrianCooney