简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM