Finding include directories and link libraries

Discussion in 'C++' started by Dave Farrance, Apr 8, 2005.

  1. What's the correct way to find the include directories and link
    libraries when compiling with gnu c++ ?

    I decided that I'd like to try out line-drawing using the GTK toolkit,
    so I copied the line drawing examples from this tutorial page:
    http://www.gtkmm.org/tutorial/sec-drawingarea.html
    I then tried to compile it with c++ on Mandrake Linux, and spent ages
    resolving the dependencies.

    I ran the compiler, looked at the first complaint about a header file
    that it couldn't include, used the "locate" command to find it on my
    machine, and if it wasn't found, search for the package containing that
    file to be downloaded, and then add that directory as a compiler include
    directive. This had to be repeated several times.

    Then the linking. At each complaint about an unresolved function, I
    tried to guess the library that was required from the name of the
    function, or from the names of the previously worked out include files,
    and from the names of libraries in the /usr/lib directory. I usually
    stumbled onto the correct library after a few attempts in each case.

    After all that work, my makefile ended up looking like this:

    gtktest : gtktest.cc
    c++ gtktest.cc -o gtktest \
    -I/usr/include/gtk-1.2 -I/usr/lib/gtkmm/include \
    -I/usr/include/glib-1.2 -I/usr/lib/glib/include \
    -I/usr/include/sigc++-1.0 \
    -lgtkmm -lsigc -lgdkmm -lpthread

    That was just to try out a tutorial. Surely it shouldn't be that hard?
    Am I going about this the wrong way?

    --
    Dave Farrance
    Dave Farrance, Apr 8, 2005
    #1
    1. Advertising

  2. Dave Farrance wrote:
    > What's the correct way to find the include directories and link
    > libraries when compiling with gnu c++ ?
    >
    > I decided that I'd like to try out line-drawing using the GTK toolkit,
    > so I copied the line drawing examples from this tutorial page:
    > http://www.gtkmm.org/tutorial/sec-drawingarea.html
    > I then tried to compile it with c++ on Mandrake Linux, and spent ages
    > resolving the dependencies.
    >
    > I ran the compiler, looked at the first complaint about a header file
    > that it couldn't include, used the "locate" command to find it on my
    > machine, and if it wasn't found, search for the package containing that
    > file to be downloaded, and then add that directory as a compiler include
    > directive. This had to be repeated several times.
    >
    > Then the linking. At each complaint about an unresolved function, I
    > tried to guess the library that was required from the name of the
    > function, or from the names of the previously worked out include files,
    > and from the names of libraries in the /usr/lib directory. I usually
    > stumbled onto the correct library after a few attempts in each case.
    >
    > After all that work, my makefile ended up looking like this:
    >
    > gtktest : gtktest.cc
    > c++ gtktest.cc -o gtktest \
    > -I/usr/include/gtk-1.2 -I/usr/lib/gtkmm/include \
    > -I/usr/include/glib-1.2 -I/usr/lib/glib/include \
    > -I/usr/include/sigc++-1.0 \
    > -lgtkmm -lsigc -lgdkmm -lpthread
    >
    > That was just to try out a tutorial. Surely it shouldn't be that hard?
    > Am I going about this the wrong way?
    >


    for gtk, glib, and friends there exist config executables that
    can be used to get the flags for compilation and linking.

    e.g.:
    c++ `gtk-config --cflags --libs` -o gtktest gtktest.cc
    Thomas Maier-Komor, Apr 8, 2005
    #2
    1. Advertising

  3. Thomas Maier-Komor <-spam.e-technik.tu-muenchen.de>
    wrote:

    >for gtk, glib, and friends there exist config executables that
    >can be used to get the flags for compilation and linking.
    >
    >e.g.:
    >c++ `gtk-config --cflags --libs` -o gtktest gtktest.cc


    Thanks. That gtk-config generates:
    -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include
    -I/usr/X11R6/include -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule
    -lglib -ldl -lXi -lXext -lX11 -lm

    .... which includes three of the five include directories that I needed,
    but none of the libraries, unfortunately. It would have saved me some
    work, though. I must watch out for these config files.

    --
    Dave Farrance
    Dave Farrance, Apr 8, 2005
    #3
  4. Dave Farrance <> wrote in message news:<>...
    > What's the correct way to find the include directories and link
    > libraries when compiling with gnu c++ ?
    >
    > I decided that I'd like to try out line-drawing using the GTK toolkit,
    > so I copied the line drawing examples from this tutorial page:
    > http://www.gtkmm.org/tutorial/sec-drawingarea.html

    [snip]
    > -I/usr/include/gtk-1.2 -I/usr/lib/gtkmm/include \
    > -I/usr/include/glib-1.2 -I/usr/lib/glib/include \
    > -I/usr/include/sigc++-1.0 \
    > -lgtkmm -lsigc -lgdkmm -lpthread

    [snip]

    You are making your life difficult by using gtkmm 1.2 (and GTK+ 1.2).
    It's ancient. The newer versions (e.g. 2.6) have far easier API. And
    they use pkg-config to make building much easier - see the gtkmm FAQ.
    Murray Cumming, Apr 9, 2005
    #4
  5. (Murray Cumming) wrote:

    >You are making your life difficult by using gtkmm 1.2 (and GTK+ 1.2).
    >It's ancient. The newer versions (e.g. 2.6) have far easier API. And
    >they use pkg-config to make building much easier - see the gtkmm FAQ.


    Thanks. I'd used gtkmm 1.2 because that tutorial was the only example
    that I found with a websearch on GTK +"line draw".

    I searched for that gtkmm FAQ you mentioned, and discovered that
    Mandrake Linux had packaged the gtkmm 2.4 documents in a separate RPM.
    There's also a substantial tutorial in there as well with a line draw
    example that did look cleaner. And pkg-config worked perfectly.

    --
    Dave Farrance
    Dave Farrance, Apr 10, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Finkel
    Replies:
    0
    Views:
    483
    Joel Finkel
    Sep 12, 2003
  2. Jeffry van de Vuurst
    Replies:
    2
    Views:
    512
    Jeffry van de Vuurst
    Jul 30, 2003
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    882
    Andreas Bogenberger
    Feb 22, 2008
  4. Adam Petrie
    Replies:
    8
    Views:
    292
    Adam Petrie
    Oct 11, 2004
  5. Ron Smith
    Replies:
    5
    Views:
    136
    Michele Dondi
    Nov 2, 2004
Loading...

Share This Page