Charlie Root wrote:
>
> I have a tiny little snippit of code here (test.c):
>
> char ldap_init();
> int main(int argc, char **argv)
> {
> ldap_init();
> return 0;
> }
>
> I expect (want) a runtime error but I do expect it to compile when
> linked with the openldap libraries. Here's my quandery:
>
> vv# gcc -L/usr/local/lib -I/usr/local/include -lldap -llber test.c
> /tmp/ccj67244.o: In function `main':
> /tmp/ccj67244.o(.text+0x7): undefined reference to `ldap_init'
>
> Very odd... but if I changed the ordering of the arguments:
>
> vv# gcc -L/usr/local/lib -I/usr/local/include test.c -lldap -llber
> vv#
>
> It compiles fine. I thought gcc proccessed files in the order in which
> they appeard? I further thought that the only difference between
> specifying a fullname and using -l was that -l surrounding the name
> with lib*.a and searched multiple directories. If thats all true why
> would the ordering matter here?
The linker, ld, searches libraries for undefined symbols. By specifying
-lldap before test.c on the command line, you told ld to scan libldap.a,
then compile test.c, which creates a reference to ldap_init that cannot
be resolved. Compiling test.c first creates the reference, which is
later resolved by searching libldap.a.
--
"Where am I, and what am I doing in this handbasket?"
Wes Peters Softweyr LLC
[EMAIL PROTECTED] http://softweyr.com/
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message