Linking a shared library with another shared lib in linux

前端 未结 3 1284
时光说笑
时光说笑 2020-11-27 04:52

I am trying to build a shared library. Let us say libabc.so .It uses another .so file , say lib123.so (a lib in /usr/local/lib) .Now i am using my shared lib libabc.so in my

3条回答
  •  天命终不由人
    2020-11-27 04:54

    Following the same procedure pointed out by Basile Starynkevitch, for example, I have a library which depends on libm.so, so the compilation for the library objects are:

    gcc -fPIC -Wall -g -I include -I src -c src/wavegen.c  -o build/arm/wavegen.o                                                                                          
    gcc -fPIC -Wall -g -I include -I src -c src/serial.c  -o build/arm/serial.o
    

    To compile the library, however, in some versions of gcc the order where library references are placed, is important, so I suggest, to ensure compatibility, placing those references at the end of the command:

    gcc -shared -Wl,-soname,libserial.so.1 -o lib/libserial.so.1.0 build/arm/wavegen.o build/arm/serial.o -lm
    

    I have tested in PC (gcc v.8.3.0) and in ARM (gcc v.4.6.3).

提交回复
热议问题