0

Another company gives me three files(demo.c,api.h,libapi.so). they told me that't enough for develop. I'm confuse how to build these thing together. I use gcc demo.c -o demo -l libapi.so . But's it's said "ld: library not found". I use Mac OS system. Some websites said i should use Linux to use .so file. what should I do?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Weijie Shi
  • 13
  • 2
  • 2
    `.so` files are not OSX. `-l libapi.so` ? Try `-lapi` flag. You may also have to provide search path for a non-standard library `-L./` (this means it is in the current directory). – user3078414 Jun 15 '16 at 20:31
  • If the so file is in your current directory try -l ./libapi.so – Bing Bang Jun 15 '16 at 20:32
  • As asked, this is not related to embedded systems! – too honest for this site Jun 15 '16 at 22:03
  • 1
    Maybe this would help: http://stackoverflow.com/a/2339910/929459 ? – Dmitri Jun 15 '16 at 22:22
  • Generally speaking, Mac OS X uses `.dylib` and `.bundle` for shared libraries (with `.dylib` being dynamic libraries loaded when the program starts and `.bundle` being libraries loaded via `dlopen()` etc after the program starts — at least in theory). It seems likely that the `.so` file is incorrect for OS X. What do you get when you run `file libapi.so` and what does `otool -L libapi.so` have to say? If the answers don't include `Mach-O`, then you're likely to need to go back to the supplier (for source or object code for OS X). Try: `gcc -o demo demo.c libapi.so` (no `-l`); it might work. – Jonathan Leffler Jun 15 '16 at 23:53
  • Note that using linker options `-l xyz` means that the linker should look for `libxyz.dylib` or `libxyz.a` on OS X. Specifying `-l libapi.so` means that the linker is looking for `liblibapi.so.dylib` or `liblibapi.so.a` and (not very surprisingly) is not finding either. – Jonathan Leffler Jun 16 '16 at 00:08

1 Answers1

-1

*.so is "shared object" it works only on Linux. The Windows counterpart of *.so is DLL.These are combiled object code.

What you have to do is 1] "compile" your .c to .o [object file] 2] "Link" the new .o file with the .so

George
  • 1,330
  • 1
  • 9
  • 12