[Nix-dev] Trying to compile and run mono gtk example but problem install gtksharp2

Vincent Laporte vincent.laporte at irisa.fr
Wed Mar 25 18:47:40 CET 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Le 2015-03-24 22:40, Paul Dufresne a écrit :
> I am trying to compile the GTK example on: 
> http://www.mono-project.com/docs/getting-started/mono-basics/
> 
> […] seems to work, but when [nix-shell:~/mycs]$ mono helloGtk.exe
> 
> Unhandled Exception: System.IO.FileNotFoundException: Could not
> load file or assembly 'gtk-sharp, Version=2.12.0.0,
> Culture=neutral,

Hello,

At compilation time, the gtk-sharp libraries are found thanks to
pkg-config.

At run time, they are searched in the paths listed in the
MONO_GAC_PREFIX environment variable.

Therefore, you need to populate this variable:

~~~
export MONO_GAC_PREFIX=/nix/store/qfk2…-gtk-sharp-2.12.10
~~~

Then you will face a different error, about glibsharpglue dll not found.

Those libraries are searched in the paths listed in the
LD_LIBRARY_PATH environment variable.

You need to populate it as well:

~~~
export LD_LIBRARY_PATH=/nix/store/…-gtk-sharp-…/lib:…
~~~

This is tedious and you may not remember all those arcane commands
next time you want to run your hello program. A solution is to wrap
your program into a launcher script, and write a nix program as follows:

~~~ default.nix ~~~
with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "gtksharp-hello";

  src = ./.;

  buildInputs = [ mono gtk-sharp pkgconfig ];

  buildPhase = "mcs ./hello.cs -pkg:gtk-sharp-2.0";

  dontStrip = true;

  installPhase = ''
    mkdir -p $out/bin
    mv hello.exe $out/bin/
    cat <<EOF > $out/bin/hello
    export MONO_GAC_PREFIX=${gtk-sharp}:\$MONO_GAC_PREFIX
    export LD_LIBRARY_PATH=${gtk-sharp}/lib:${gtk}/lib:\$LD_LIBRARY_PATH
    ${mono}/bin/mono ./hello.exe
    EOF
    chmod +x $out/bin/hello
  '';
}
~~~

Then, running `nix-build` will compile the source and write the
launcher script that sets correctly the environment variables.

Hope this helps,
- --
Vincent.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJVEvS0AAoJEEEW/4F+UwyXDNsP/ilClovGraLSXhE/a6ybsDBg
Tyupka+PdSaAIK1ajXqcbYB3MWn2dICxXdeZjahpfznabfgtnHNGamVguhLPOCJz
DroCyStCD5GrCrKCPrnCx1qdc0cE4jzN/nlVToESqMRMd7xKSdmHchceqtYsAEgv
HxSdslXexay2TC96z/NjkXMCD6sxt6io6kMUo8x2DW04SwT4KDw7Dz0DFv0Fn6JT
a8Y5XztzmWfaHZ0PYZQxcIZTV8xtQ72+OU5jbeEk8JoETmCaTgt43TEkH1E7bMYO
OzUzYbqH4C/AtyFb1NLozI1vo7BFzMilZA6oKanlXKExjdzgpjjKse3Y9p8lQuCF
KztpnWSDKbQYjs161YLNBEC+hIP6mRVQGfXQUc/xQXka6kML0QOyNh5c7v6tJ3VA
303djCNJcSXBwt9F5ahuh2Rc+xAxY+Dr3IWYr9IOlhfvWUkUcMuO4le2TiOy4aHR
vGUjn+bn3+NW7gqjseTdtYZWg3u/dl6jfJMqb01nHmLVLAGYDDH5VApOVAN/g47c
rIrqGQd85vcFK0mlMsmakcQxmmktf1+5ITCoNmsKexGJfIDOUw/vqcZDItwIeJDa
2pEK71LjZ9NcjvF7VjlmkUnbQbsTMsVFlFQNIImQs9z9S5S/p1av+nMNM6jw9fiI
rZiFZO5YWkhPiKqsxa65
=kw1o
-----END PGP SIGNATURE-----


More information about the nix-dev mailing list