Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newbie Question: GTK# (Mono) on OSX

Tags:

macos

mono

gtk#

I am taking my first steps (or perhaps my last steps) in GTK# on Mono for OSX. I write a .cs file and then try to compile with mono:

gmcs -pkg:gtk-sharp-2.0 one.cs

this results in this message

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

Which would, apparently, require me to know what I'm doing. I do know that

Mono's Installer for MacOS X comes with Gtk+ and Gtk# so you can start building and running cross-platform GUI Gtk# applications that include OSX."

So there's nothing to install.

I do find GTK2 here

/opt/local/var/macports/sources/rsync.macports.org/release/ports/x11/gtk2/

which was definitely installed by the Mono installation.

Gmcs version is 2.4.2.2.

Edit: Miguel says I have something weird in my path.

I have removed all Macports following Macports instructions. I have reinstalled Mono from the .dmg. Here is my current path

export PATH=/opt/subversion:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin

but even if use just /usr/bin it's still not avoiding the error.

ALL Mono stuff is where it's supposed to be, including all the stuff in /Library/Frameworks/Mono.framework/Versions/Current. HOWEVER: strangely

/Library/Frameworks/Mono.framework/Versions/2.4.2.2/lib/gtk-sharp-2.0/ 

is empty. But MonoDevelop runs, but doesn't know about Gtk (I've included all the references it knows about)...

like image 767
Dan Rosenstark Avatar asked Aug 02 '09 21:08

Dan Rosenstark


3 Answers

Quick and dirty solution:

cd /usr/local/bin
sudo ln -s /Library/Frameworks/Mono.framework/Commands/pkg-config ./pkg-config

Now your gmcs -pkg:... command will work.

Background: I hit this exact problem on a new Mac and a fresh install of Mono. Left me scratching my head for a few days until I took a close look at the error message:

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

It's saying it couldn't run the program, so I did a

which pkg-config

That came up blank, so I thought probably it couldn't run it because it wasn't in the path. And that turned out to be it.

like image 126
Yawar Avatar answered Sep 27 '22 18:09

Yawar


You have a mixed setup.

The Gtk in /opt/local/var/macports did not come from Mono's installer for OSX, you probably got it earlier from macports. The Mono installer places its files under /Library/Frameworks/Mono.framework/

Chances are, you have something else on your path, since it works out of the box after I installed the Mono.Framework from the Mono web site (with the command line example that you have above).

like image 37
miguel.de.icaza Avatar answered Sep 27 '22 19:09

miguel.de.icaza


Using MonoDevelop might make things easier, but here is how it references gtk# while compiling (note that it references the assembly straight from the GAC):

gmcs test.cs -r:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gac/gtk-sharp/2.12.0.0__35e10195dab3c99f/gtk-sharp.dll

You'll usually also need to include references to gdk-sharp and pango-sharp and glib-sharp, btw.

Note in the path that the framework version is "Current", which makes the command a little more future-proof.

like image 26
Sandy Avatar answered Sep 27 '22 20:09

Sandy