0

I am having libcommon.so in the /usr/local/lib and I am linking this library in my program.

gcc -o test test_prog.c -L/usr/local/lib -llibcommon.so

and I have tried this too

gcc -o test test_prog.c -L/usr/local/lib -llibcommon

It's giving

/usr/bin/ld: cannot find -llibcommon.so
collect2: ld returned 1 exit status

It is there:

$ locate libcommon.so
/usr/local/lib/libcommon.so
/usr/local/lib/libcommon.so.0
/usr/local/lib/libcommon.so.0.1.0
$
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user2732944
  • 75
  • 2
  • 4
  • 10
  • you can check [here](https://stackoverflow.com/questions/31948521/building-error-using-cmake-cannot-find-lpthreads/52069326#52069326) – Aditya Pawaskar Aug 29 '18 at 04:08

3 Answers3

8

When you use the -l, you specify just the 'basic' library name:

-lcommon

This will track down libcommon.so in some directory.

You told the compiler to try and find liblibcommon.so.so (and liblibcommon.so) and it probably couldn't...indeed, you wouldn't be asking the question if it could.

Some GNU programs build a library libiberty.so (or its equivalent), so the link lines using the library link with:

-liberty

(which is funny; GNU would really rather it was +liberty, but ... you can't fix everything).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • i am getting this after changing according to you /usr/local/lib /libcommon.so.0: could not read symbols: Invalid operation collect2: ld returned 1 exit status – user2732944 Sep 05 '13 at 15:13
  • Now you have a different problem. The linker finds the library, but can't make sense of what is in it. I suggest starting by running `file /usr/lib/libcommon.so /lib/libc.so` and looking to see if there's an obvious difference between the file types. You may have to follow symlinks (so you may have to specify a different names in the `file` command line. If there's a big difference, then you may have installed the wrong file(s) — or the system administrator may have done that. – Jonathan Leffler Sep 05 '13 at 15:18
1

Use -lcommon switch when you link libcommon.so

sr01853
  • 6,043
  • 1
  • 19
  • 39
1

try to export LD_LIBRARY_PATH pointing to the directory where you have kept the so files .

export LD_LIBRARY_PATH = /pathofdirectorywheresofilesarekept

vineet pant
  • 77
  • 1
  • 9