From what I have learned I need to follow this step to prepare for making a shared library:
gcc -fPIC libfoo.c -o libfoo.o
And then I link it. I had tried making a makefile to aid in these steps, but there appears to be errors happening now.
This occurs when I run the make file:
foo@box:~/Projects/so$ gcc -fPIC ./libfoo.c -o libfoo.o
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
How can I compile the library file without the main function, as it is not a program and is intended to be a library?
If it helps my program is basically this (interpreted)
(stdio and openssl headers here)
(debugging macro definitions here)
(two functions, gettime() and opensslrandom() defined here)
I seem to have problems understanding about the macros as well, as they would be in the shared library in the end they are useless in the shared library? I included them in libfoo.h to be included, although I have yet to see if the macros work.
The -shared or -dynamiclib option is required to create a shared library.
A shared object is an indivisible unit that is generated from one or more relocatable objects. Shared objects can be bound with dynamic executables to form a runable process. As their name implies, shared objects can be shared by more than one application.
LIBS = -L$(LIB) -lfuse -lsqlite3 -lkw_taglib -ltag_c -ltag -Wl,-rpath=. So the binary will search in the current directory for dyn-libraries. However, you add ../lib to your LD_LIBRARY_PATH later, for execution of the binary, so the given path .
You need -c
gcc -fPIC -c libfoo.c
for generating the object files.
You may want to look at: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With