sirius27
sirius27

Reputation: 211

Why doesn't putting my own C library file into ld search path work?

Currently I have two files

main.c
libxxx.a

main.c references some functions defined in the source code of a relocatable object file in libxxx.a.

Now the following command successfully compiles main.c and links it to libxxx.a:

gcc -o prog main.c libxxx.a

but if I put libxxx.a into one of the search paths of ld, the same directory with libc.a,

gcc -o prog main.c

just doesn't work. It seems that ld fails to find this archive file when searching in the directory. Can someone tell me why this happens?

Upvotes: 0

Views: 52

Answers (1)

Employed Russian
Employed Russian

Reputation: 213706

but if I put libxxx.a into one of the search paths of lb linker, the same directory with libc.a,

gcc -o prog main.c

just doesn't work.

That is expected and desired: you wouldn't want every program you write to link against every library that is installed in the system search path. What you want is:

gcc -o prog main.c -lxxx

That is: copying the library into /usr/lib allows the linker to find it without any extra search arguments, but you still must tell the linker that you want to link against libxxx.

Upvotes: 1

Related Questions