C: compile some objects (for a shared library) without main() fails?

17,452

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

Share:
17,452
Tim N.
Author by

Tim N.

Updated on July 29, 2022

Comments

  • Tim N.
    Tim N. almost 2 years

    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.

  • Tim N.
    Tim N. about 13 years
    Brilliant, I knew there was something simple!