Ishpeck
Ishpeck

Reputation: 2041

ld can't see a library I just built

I'm not able to link with my .so

[0] [ishpeck@yoshimitsu segfaulty]$ cat Makefile 
all: ishy_crashy.so main.c
    gcc -L. -lishy_crashy -o crashy main.c

ishy_crashy.so: libby.h libby.c
    gcc -fPIC -shared -Wl,-soname,ishy_crashy -o ishy_crashy.so libby.c
[0] [ishpeck@yoshimitsu segfaulty]$ make
gcc -fPIC -shared -Wl,-soname,ishy_crashy -o ishy_crashy.so libby.c
gcc -L. -lishy_crashy -o crashy main.c
/usr/bin/ld: cannot find -lishy_crashy
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
[2] [ishpeck@yoshimitsu segfaulty]$ file ishy_crashy.so 
ishy_crashy.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x0bcbdf5d7d1b88222ee057c014c906cd9fdd859d, not stripped
[0] [ishpeck@yoshimitsu segfaulty]$ echo $LD_LIBRARY_PATH

[0] [ishpeck@yoshimitsu segfaulty]$ export LD_LIBRARY_PATH=.:`pwd`:/lib:/usr/lib:/usr/local/lib
[0] [ishpeck@yoshimitsu segfaulty]$ make
gcc -L. -lishy_crashy -o crashy main.c
/usr/bin/ld: cannot find -lishy_crashy
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
[2] [ishpeck@yoshimitsu segfaulty]$ ls
ishy_crashy.so  libby.c  libby.h  main.c  Makefile
[0] [ishpeck@yoshimitsu segfaulty]$ echo $LD_LIBRARY_PATH
.:/tmp/segfaulty:/lib:/usr/lib:/usr/local/lib

What'm I missing?

Upvotes: 1

Views: 732

Answers (2)

Barmar
Barmar

Reputation: 782285

The argument -lishy_crashy means to look for libishy_crashy.so or libishy_crashy.a. You're missing the lib prefix on the library filename.

Upvotes: 1

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272687

Because the naming convention for libraries is to have the prefix lib. Standard tools understand that, so -lxyz looks for a library called libxyz.so/libxyz.a.

Upvotes: 1

Related Questions