public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] OT -- gcc .o linking and undefined references
@ 2005-10-23  3:20 Dan
  2005-10-24  8:41 ` Christoph Gysin
  0 siblings, 1 reply; 2+ messages in thread
From: Dan @ 2005-10-23  3:20 UTC (permalink / raw
  To: gentoo-user

Hi everyone, I'm doing something really obviously wrong, but I don't 
know what.

I can gcc -c -o file.o file.c  and get a binary object.

I do this for the main and two "helper" .c files

This works, then I get a bunch of .o files.

then you usually do

gcc -o <final executable name> <main.o> <myfile1.o> <myfile2.o>

and gcc does the linking.

In thsi case, myfile2.c uses ldap_init and ldap_simple_bind, and 
myfile2.h inludes ldap.h.

At this point, there is no ldap.o, just the ldap.h from 
/usr/include/ldap.h so compile of everything stalls, saying that there 
is an undefined reference to the function ldap_init and ldap_simple_bind.

Testing indicates that you can do:

int main() {
thingy_do(123);
}

and it will happily do a gcc -c -o main main.c  and create the object, 
which is what it should -- it's not until we link .o's to create a real 
executable that the system wants to make sure the executable code exists.

The bit that makes me think I'm stupid is that it seems that neither gcc 
or I can find the source (.c) or compiled binaries (.o) which implement 
the structures and functions defined in ldap.h.  What am I doing wrong?  
Where are the .c and .o files supposed to be on a regular linux system? 
Where on gentoo? Have I missed a crucial flag?

Thanks in advance...

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [gentoo-user] OT -- gcc .o linking and undefined references
  2005-10-23  3:20 [gentoo-user] OT -- gcc .o linking and undefined references Dan
@ 2005-10-24  8:41 ` Christoph Gysin
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Gysin @ 2005-10-24  8:41 UTC (permalink / raw
  To: gentoo-user

Dan wrote:
> The bit that makes me think I'm stupid is that it seems that neither gcc 
> or I can find the source (.c) or compiled binaries (.o) which implement 
> the structures and functions defined in ldap.h.  What am I doing wrong?  
> Where are the .c and .o files supposed to be on a regular linux system? 
> Where on gentoo? Have I missed a crucial flag?

Openldap (like most software) installs its code in libraries under /usr/lib. 
They are called lib<name>.a (static) or lib<name>.so (dynamic). In your case the 
file is called /usr/lib/libldap.so. But you don't really need to know that. To 
compile your code, simply type:

gcc -o <your_prog> main.o myfile1.o myfile2.o -lldap

Where -lldap means: link against libldap.

Christoph
-- 
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-10-24 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-23  3:20 [gentoo-user] OT -- gcc .o linking and undefined references Dan
2005-10-24  8:41 ` Christoph Gysin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox