title: GtkSharp 3.22 for Mono
body: <p>I need to write a Gtk# application using Mono in a Linux environment. As I need specific features present in >=3.22 I can't use the default Gtk2 library.</p>
  
  <p>Steps tried so far:</p>
  
  <ol>
  <li>Installing Gtk3 library version 3.22.24.0 <code>sudo apt-get install libgtk-3-dev</code>.</li>
  <li>In MonoDevelop, installing this <a href="https://libraries.io/nuget/gtk-sharp-3" rel="nofollow noreferrer" title="Gtk# 3">package</a> that should provide the most up-to-date Gtk# bindings, version 3.22.6.4.</li>
  </ol>
  
  <p>Running a simple Gtk# application (as simple as <code>Gtk.Application.Init()</code> in main) triggers the following exception:</p>
  
  <pre><code>System.DllNotFoundException: libgtk-3.so.0
  </code></pre>
  
  <p>despite <code>ldconfig -p | grep libgtk</code> returning such a file under <code>/usr/lib/x86_64-linux-gnu</code>.</p>
  
  <p>I feel like I'm missing something very obvious here. I'm running Ubuntu 17.10 (x86), MonoDevelop 7.1 build 1291.</p>
  
  <p>EDIT -- the issue is with MonoDevelop being installed via Flatpak, which provides a sandbox environment that "shields" the application from outside references, including the Gtk libraries. Therefore I installed Mono and compiled MonoDevelop following <a href="https://kvssoft.wordpress.com/2016/12/13/building-monodevelop-on-ubuntu/" rel="nofollow noreferrer" title="How to build monodevelop">this guide</a> almost verbatim:</p>
  
  <ol>
  <li><p>Add the repo list and update everything (Ubuntu's "factory-default" repos come with a 4.something version of Mono, which is not enough to compile Monodevelop as it lacks MSBuild):</p>
  
  <pre><code>sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-official.list
  sudo apt update &amp;&amp; sudo apt upgrade -y
  </code></pre></li>
  <li><p>Install required dependencies:</p>
  
  <pre><code>sudo apt install -y autoconf automake cmake fsharp git gnome-sharp2 gtk-sharp2 libssh2-1-dev mono-complete referenceassemblies-pcl zlib1g-dev
  </code></pre></li>
  <li><p>Clone Monodevelop from git, with X being the version we choose from <a href="https://github.com/mono/monodevelop/releases" rel="nofollow noreferrer" title="Monodevelop releases">here</a> (tested with 7.3.0.708) and last argument being the folder where the source will be located:</p>
  
  <pre><code>git clone https://github.com/mono/monodevelop.git --branch monodevelop-X --depth 1 X
  </code></pre></li>
  <li><p>Configure, make and make install:</p>
  
  <pre><code>./configure --profile=stable --enable-release
  make
  sudo make install
  </code></pre></li>
  <li><p>Install GtkSharp 3:</p>
  
  <pre><code>sudo apt-get install libgtk-3-dev
  </code></pre></li>
  </ol>
  
  <p>And that's it. Applications developed with the aforementioned <a href="https://libraries.io/nuget/gtk-sharp-3" rel="nofollow noreferrer" title="Gtk# 3">package</a> will then work correctly.</p>
  
  <p>For some reason my app crashes when ran from within MonoDevelop (something to do with Glade files imported by <code>Builder.ExtendWithTemplate</code>) but works from command line <code>mono &lt;appname&gt;.exe</code>, so my solution might not be the best one, but that's a start.</p>