By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,890 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,890 IT Pros & Developers. It's quick & easy.

Finding include directories and link libraries

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Jul 23 '05 #2

P: n/a
Thomas Maier-Komor <ma******@lpr.no-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
Jul 23 '05 #3

P: n/a
Dave Farrance <Da**********@OMiTTHiSyahooANDTHiS.co.uk> wrote in message news:<nh********************************@4ax.com>. ..
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.
Jul 23 '05 #4

P: n/a
mu*****@murrayc.com (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
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.