How to make .so file with libtool

2.2k views Asked by At

I am currently using the following method to create shared libraries:

gcc -c test1.c -fPIC -o test1.o
gcc -c test2.c -fPIC -o test2.o
...
gcc test1.o test2.o ... -shared -o libtest.so

How can I do this same task with libtool? This is what I have done so far:

libtool compile gcc -c test1.c -o test1.o
libtool compile gcc -c test2.c -o test2.o
...
libtool link gcc test1.lo test2.lo ... -o libtest.la

However, this only creates libtest.la and libtest.a. I need the shared library libtest.so.

2

There are 2 answers

0
fchen On

I was bothered by this problem for quite a while until later I read carefully through the log file from configure, the script detects that LD was not able to generate dynamic linked file (.so). The problem was my environment variable LD was set to g++. Unset it or change to ld fixed the problem.

0
Ling Yan On

Try to add -rpath option like: libtool --mode=link gcc -o libtest.la test1.lo -rpath /tmp

-rpath option tells Libtool where to install the library If the path's missed, it won't generate the shared library.