cannot compile gtk# example

2019-07-21 16:07发布

问题:

I'm trying to compile the "GTK# Hello World" example at http://mono-project.com/Mono_Basics in Windows 7 (64bits). I'm getting this error:

error CS8027: Couldn't run pkg-config: ApplicationName='pkg-config', CommandLine ='--libs gtk-sharp-2.0', CurrentDirectory=''

I have successfully compiled and run the "Console Hello World" example.

I have installed Mono-2.10.8.

Thanks in advance for your help

回答1:

I tried to compile a GTK# example in a Windows 7 with Mono 2.10.8 and the options you used with the compiler, so i have the same error then i tried to reference each assembly by hand so it works fine.

Here is the full command, i tested in a Mono 2-10.8 comman prompt.

gmcs ButtonApp.cs -r:C:/PROGRA~2/MONO-2~1.8/lib/mono/gtk-sharp-2.0/pango-sharp.dll,C:/PROGRA~2/MONO-2~1.8/lib/mono/gtk-sharp-2.0/atk-sharp.dll,C:/PROGRA~2/MONO-2~1.8/lib/mono/gtk-sharp-2.0/gdk-sharp.dll,C:/PROGRA~2/MONO-2~1.8/lib/mono/gtk-sharp-2.0/gtk-sharp.dll

I hope this can helps



回答2:

You were trying to use pkg-config which you do not have. pkg-config with --libs turns specified packages (like gtk-sharp-2.0 in your case) into references to libraries. If you don't want to install pkg-config, you have two options:

  • manually reference needed libraries with compiler options;
  • create a project with these libraries referenced.

I recommend the second option, as compiling by specifying all sources and references directly could be good for hello-world examples, but not for the something bigger. You would make your own script to compile the project, so why not use something designed just for that - like xbuild or make. MonoDevelop should contain empty Gtk# project template.