Gentoo Archives: gentoo-amd64

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-amd64@l.g.o
Subject: [gentoo-amd64] Re: How does gcc find a library?
Date: Sun, 17 May 2009 20:13:37
Message-Id: pan.2009.05.17.20.13.22@cox.net
In Reply to: [gentoo-amd64] How does gcc find a library? by Mark Knecht
1 Mark Knecht <markknecht@×××××.com> posted
2 5bdc1c8b0905170849j3e0198ebrf29bc2042dda7ee4@××××××××××.com, excerpted
3 below, on Sun, 17 May 2009 08:49:13 -0700:
4
5 > Hi,
6 > I'm trying to compile a new piece of software for MythTV hardware
7 > support that's not in portage. I'm not a programmer so I'm woefully
8 > uneducated in this area but how does gcc find a library that a piece of
9 > code is requiring?
10
11 Well, I'm not a programmer either, but I think I understand a bit about
12 this just from troubleshooting various ebuilds over time. YMMV, but the
13 below is what I'd try.
14
15 gcc looks in various standard system locations (/usr/include, among
16 others) automatically for the header files, which tell it the interfaces
17 the library supplies. The interfaces consist of the the functions, etc,
18 along with the parameters they take, their orders and their types (int,
19 string pointer, whatever).
20
21 For header files not found in the standard locations and not in the
22 working dir that's being compiled, gcc has the -I<includedir> parameter,
23 among others.
24
25 Then for linking, there's -L<linkdir>, if you find you need it later.
26
27 > My code setup is this:
28 >
29 > /home/mark/scte65scan-0.2
30 > /home/mark/scte65scan-0.2/libhdhomerun
31
32 > The code all exists in the scte65scan directory. The required library is
33 > in libhdhomerun.
34 >
35 > When I attempt to build the code I get the error message:
36 >
37 > mark@Sector9 ~/scte65scan-0.2 $ make -f Makefile.hdhr cc -O2 -DHDHR -c
38 > tunerdmx.c -o tunerdmx.o tunerdmx.c:39:23: error: hdhomerun.h: No such
39 > file or directory
40
41 > So it seems it cannot find the library because hdhomerun.h is in
42 > the libhdhomerun diectory:
43
44 > The tunerdmx.c program has an include for hdhomerun:
45 >
46 > #ifdef HDHR
47 > #include "hdhomerun.h"
48 >
49 > which is what I guess is kicking off the problem. The makefile looks
50 > like this:
51 >
52 > mark@Sector9 ~/scte65scan-0.2 $ cat Makefile.hdhr
53 > HDHR_DIR=./libhdhomerun
54
55 That part looks right, since it's a subdir, and the (snipped) LIBOBJS
56 point into it as expected.
57
58 > CFLAGS += -O2 -DHDHR
59 > LDFLAGS += -lpthread
60
61 > So, how do I tell gcc that the library is here so it can build it?
62
63 Add to that CFLAGS line: -I./libhdhomerun . See if that helps. You can
64 try the absolute form too (/home/mark...) but that can cause problems if
65 things are moved around, later. The relative form should help avoid
66 those problems.
67
68 If you later get hungup in linking, there's the -L<dir> parameter for
69 that, too, but I'd not add it until it looks like it's needing it.
70
71 As I said above, this is troubleshooting level knowledge. Try it and see
72 if it works more than really understanding the full implications, tho I
73 believe I understand why it /should/ work, as explained above -- you're
74 simply pointing gcc at the right dirs.
75
76 --
77 Duncan - List replies preferred. No HTML msgs.
78 "Every nonfree program has a lord, a master --
79 and if you use the program, he is your master." Richard Stallman

Replies

Subject Author
Re: [gentoo-amd64] Re: How does gcc find a library? Mark Knecht <markknecht@×××××.com>