1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Compiling GTK in Xterm

Discussion in 'Mac Programming' started by ScKaSx, Jul 12, 2006.

  1. macrumors regular

    #1
    Hi All,

    I downloaded gtk2.0 using fink. I was working on a tutorial for gtk however for some reason I seem to be unable to compile the gtk properly. If I did my research correctly the way you compile a gtk file in xterm is as follows:

    gcc code.c -o code `pkg-config --cflags --libs gtk+-2.0'

    However, this gives me the error that there is " gcc: no such file or directory called pkg-config" and then lists the file errors as a result of not finding pkg-config. So I'm guessing that I don't have pkg-config properly installed or installed at all.

    Plz, if pkg-config needs to be installed separately from gtk where do I get it? And what do I need to do to get a file such as 'code.c' to compile? Thanks

    Cheers,
    ScKaSx
     
  2. Moderator

    yellow

    Staff Member

    #2
    One question: Why aren't you letting fink do the compilation for you? "fink install gtk+2" BOOM away it goes, including all dependancies that it needs to download/compile.

    EDIT: removed incorrect info
     
  3. macrumors member

    #3
    Yes, pkg-config needs to be installed separately if you want to use that method instead of figuring out all the flags you need for GTK apps. It wasn't installed automatically because GTK doesn't actually depend on it, but fink should have it in their packages, though it's probably called "pkgconfig" like it is in DarwinPorts. Once you've installed that as well, compilation should work fine with what you're doing.

    P.S. You are trying to compile a GTK application, and not GTK itself, right?
     
  4. macrumors 6502a

    #4
    I don't know if that is a typo, but the pkg-config --cflags --libs gtk+-2.0 needs to be within backticks (`). You have finished it off with a single quote.

    pkg-config is a programme that reads a parameter file and spouts all the necessary build arguments back to the command line so you don't have to worry about long and tedious arguments to gcc.

    You can apt-get it although I would have thought it comes with gtk+2-dev, but possibly not. IIRC, you will also have to set an environment variable PKG_CONFIG_PATH to point to the config files (it has been over 2 years since I last used GTK, so I am a bit hazy on the exact set up - after installing there will be a load of files like gtk+-2.0.pc somewhere under either lib or include, which is the path you need).
     
  5. Moderator

    yellow

    Staff Member

    #5
    FWIW, fink somewhere along the line built pkgconfig for me (I assume when GTK+2 was built).
     
  6. macrumors regular

    #6
    making headway

    Hey guys,

    Thanks for the response. I was referring to compiling a gtk file such as code.c. I've tried all your suggestions and have made some headway but it's still not working:

    yellow: I tried installing gtk using 'fink install gtk' and it did some magic but not as much as when I tried your suggestion 'fink install gtk+2'. So now I believe I have the complete gtk package installed.

    Yuvi: Thanks for that fact, but after trying to install pkgconfig, alas it seems I've already installed it.

    Almost_There: Thanks for the noticing the single quotations, I wasn't making that distinction and now shows me the new error:

    Package gtk+-2 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-2.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-2' found

    If anyone knows how to resolve this issue, I'd greatly appreciate it. Thanks.

    Cheers,
    ScKaSx
     
  7. macrumors 6502a

    #7
    Search you hard disk for gtk-2.0.pc (or any file ending .pc). I don't know if Spotlight indexes /sw used by fink, though. In Terminal, I would try find /sw -name '*.pc'

    It should return the path to one or more .pc files, including gtk+-2.0.pc.
    Then type export PKG_CONFIG_PATH=/path/to/pc/file/directory

    If you are going to use this regularly, put the same export line in .profile in your home directory.
     
  8. macrumors regular

    #8
    Okay, so I tried your suggestion and searched but didn't find "gtk+-2.pc", only "gtk+.pc."

    I tried compiling with that, but it still had trouble locating libraries needed to compile a simple helloworld.c program. Anymore suggestions?!?

    I imagine that the gtk+-2.pc file is somewhere since I compiled gtk2 with Fink. Thanks

    Cheers,
    ScKaSx
     
  9. Moderator

    yellow

    Staff Member

    #9
    Strange, my install finds it just fine.

    Code:
    yellow% sudo find /sw -name "*.pc" -print
    /sw/lib/pkgconfig/atk.pc
    /sw/lib/pkgconfig/gdk-2.0.pc
    /sw/lib/pkgconfig/gdk-pixbuf-2.0.pc
    /sw/lib/pkgconfig/gdk-pixbuf-xlib-2.0.pc
    /sw/lib/pkgconfig/gdk-x11-2.0.pc
    /sw/lib/pkgconfig/gdk.pc
    /sw/lib/pkgconfig/glib-2.0.pc
    /sw/lib/pkgconfig/glib.pc
    /sw/lib/pkgconfig/gmodule-2.0.pc
    /sw/lib/pkgconfig/gmodule-no-export-2.0.pc
    /sw/lib/pkgconfig/gmodule.pc
    /sw/lib/pkgconfig/gobject-2.0.pc
    /sw/lib/pkgconfig/gthread-2.0.pc
    /sw/lib/pkgconfig/gthread.pc
    [B]/sw/lib/pkgconfig/gtk+-2.0.pc[/B]
    /sw/lib/pkgconfig/gtk+-x11-2.0.pc
    /sw/lib/pkgconfig/gtk+.pc
    /sw/lib/pkgconfig/gtk-doc.pc
    /sw/lib/pkgconfig/libexslt.pc
    /sw/lib/pkgconfig/libpng.pc
    /sw/lib/pkgconfig/libpng12.pc
    /sw/lib/pkgconfig/libxml-2.0.pc
    /sw/lib/pkgconfig/libxslt.pc
    /sw/lib/pkgconfig/pango.pc
    /sw/lib/pkgconfig/pangoft2.pc
    /sw/lib/pkgconfig/pangox.pc
    /sw/lib/pkgconfig/pangoxft.pc
    
     
  10. macrumors regular

    #10
    Yeah that is strange because this is the list I get:

    /sw/lib/freetype219/lib/pkgconfig/freetype2.pc
    /sw/lib/pkgconfig/atk.pc
    /sw/lib/pkgconfig/gdk.pc
    /sw/lib/pkgconfig/glib-2.0.pc
    /sw/lib/pkgconfig/glib.pc
    /sw/lib/pkgconfig/gmodule-2.0.pc
    /sw/lib/pkgconfig/gmodule-export-2.0.pc
    /sw/lib/pkgconfig/gmodule-no-export-2.0.pc
    /sw/lib/pkgconfig/gmodule.pc
    /sw/lib/pkgconfig/gobject-2.0.pc
    /sw/lib/pkgconfig/gthread-2.0.pc
    /sw/lib/pkgconfig/gthread.pc
    /sw/lib/pkgconfig/gtk+.pc
    /sw/lib/pkgconfig/gtk-doc.pc
    /sw/lib/pkgconfig/imlib.pc
    /sw/lib/pkgconfig/imlibgdk.pc
    /sw/lib/pkgconfig/libexslt.pc
    /sw/lib/pkgconfig/libpng.pc
    /sw/lib/pkgconfig/libpng12.pc
    /sw/lib/pkgconfig/libxml-2.0.pc
    /sw/lib/pkgconfig/libxslt.pc
    /sw/lib/pkgconfig/pango.pc
    /sw/lib/pkgconfig/pangoft2.pc
    /sw/lib/pkgconfig/pangox.pc
    /sw/lib/pkgconfig/pangoxft.pc
    /sw/lib/pkgconfig/qt-mt.pc
    /sw/share/pkgconfig/gtk-doc.pc

    It's interesting to note that all my *2.0.pc are the only ones missing. Although I installed gtk+2 from fink so I don't know why some of the files wouldn't have been installed. Is there a way I could rebuild the package? Also, I'm running OS 10.3.9, do I need to update the OS or something? Thanks.

    Cheers,
    ScKaSx
     
  11. Moderator

    yellow

    Staff Member

    #11
    You know, on another forum I've been struggling with a weird install of ethereal via fink on Panther and it just won't work like it should. On a vanilla box. Weird.

    Unfortunately I'm no where near my office so I can't check what distribution gtk+2 is part of.
     
  12. macrumors 6502a

    #12
    Do you actually have libgtk2 installed?
    It should be in /sw/lib

    I would expect you to need to the gtk+2-dev package, although I could be wrong.

    Can you list the output from

    fink list -i gtk
     
  13. macrumors regular

    #13
    Hi AlmostThere. Here's the list I get from that command:

    (i) gtk+ 1.2.10-28 The Gimp Toolkit
    (i) gtk+-data 1.2.10-28 The Gimp Toolkit
    (i) gtk+-shlibs 1.2.10-28 The Gimp Toolkit
    i gtk+2 2.6.10-1 The Gimp Toolkit
    i gtk+2-shlibs 2.6.10-1 The Gimp Toolkit
    (i) gtk-doc 1.6-2 GTK+ - API documentation generator

    Anything obviously wrong? I imagine that the i's not in parenthesis's is a bad thing. Thanks for following up.

    Cheers,
    ScKaSx
     
  14. macrumors 6502a

    #14
    Try:

    fink install gtk+2-dev

    generally the packages you need to develop with these libraries come in the *-dev packages (although I speaking mostly from a Linux point of view, not specifically fink / OS X), which hopefully contains the necessary *.pc files.
     
  15. Moderator

    yellow

    Staff Member

    #15
    Actually, the i NOT in parens is a normal, up-to-date install.
    I believe that the (i) is an outdated package?

    Try updating.

    fink selfupdate
    (when that's done)
    fink update-all
     
  16. macrumors regular

    #16
    You guys rock! You're suggestions seemed to have worked. Thanks a bunch!!!

    Cheers,
    ScKaSx
     

Share This Page