LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   linux dynamic libraries (https://www.linuxquestions.org/questions/programming-9/linux-dynamic-libraries-32127/)

aizkorri 10-07-2002 10:50 AM

linux dynamic libraries
 
I want to create Makefile that builds a .so library, but I only find examples that create .a libraries. So,
Does someone of you know which are the main differences between a .so and a .a library? Are they the same thing?
thanks.
cheers,
Aizkorri.

crabboy 10-07-2002 01:52 PM

Take a look at this example that builds a shared object and uses that so to build an executable.

$ cat loadtest.c
Code:

#include <stdio.h>

#include "test.h"

main()
{
  test();
}

$ cat test.c
Code:

#include <stdio.h>
#include "test.h"

void test()
{
  printf("Hello dude");
}

$ cat test.h
Code:

void test();

$ cat makefile
Code:

all:        testme

test.o:        test.h
        gcc -c test.c

libtest.so:        test.o
        gcc -shared -o libtest.so test.o

loadtest.o:       
        gcc -c loadtest.c

testme:        loadtest.o libtest.so
        gcc -o testme loadtest.o -L. -ltest

clean:
        rm -f *.o libtest.so testme


aizkorri 10-08-2002 06:44 AM

Thanks a lot, now I have a little idea on how to build a .so, but I'm getting this output when doing "make" and ./testme:

> ls

>loadtest.c Makefile test.c test.h

>make

>gcc -c loadtest.c
>gcc -c test.c
>gcc -shared -o libtest.so test.o
>gcc -o testme loadtest.o -L. -ltest

>ls

>libtest.so loadtest.c loadtest.o Makefile test.c test.h testme >test.o

>./testme

>./testme: error while loading shared libraries: libtest.so: cannot >open shared object file: No such file or directory

But libtest.so it there!?!?

Do you know what is wrong?. (I think the code you gave me is ok)
cheers,
Aizkorri.

crabboy 10-08-2002 09:55 AM

The dynamic linker cannot find your shared object. You either need to put the directory in /etc/ld.so.conf and run ldconfig, or modify you LD_LIBRARY_PATH environment variable.

Since you are just testing I recommend the env variable.

Code:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/shared/object

aizkorri 10-09-2002 03:26 AM

Thank you, now it's working.


All times are GMT -5. The time now is 07:10 PM.