Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Finding include directories and link libraries

Reply
Thread Tools

Finding include directories and link libraries

 
 
Dave Farrance
Guest
Posts: n/a
 
      04-08-2005
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
 
Reply With Quote
 
 
 
 
Thomas Maier-Komor
Guest
Posts: n/a
 
      04-08-2005
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
 
Reply With Quote
 
 
 
 
Dave Farrance
Guest
Posts: n/a
 
      04-08-2005
Thomas Maier-Komor <>
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
 
Reply With Quote
 
Murray Cumming
Guest
Posts: n/a
 
      04-09-2005
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.
 
Reply With Quote
 
Dave Farrance
Guest
Posts: n/a
 
      04-10-2005
(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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Directories and Physical directories Paul M Fin MCAD 4 06-27-2008 07:50 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
Extracting Directories and Sub Directories and Counting Ron Smith Perl Misc 5 11-02-2004 11:23 PM
Getting all directories/files from current directory and using -d flag for the directories Adam Petrie Perl Misc 8 10-11-2004 01:28 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57