[英]C: compile some objects (for a shared library) without main() fails?
从我学到的知识,我需要按照以下步骤准备制作共享库:
gcc -fPIC libfoo.c -o libfoo.o
然后,我将其链接。 我曾尝试制作一个makefile来帮助执行这些步骤,但是现在似乎发生了错误。
运行生成文件时会发生这种情况:
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
没有主要功能的我该如何编译该库文件,因为它不是一个程序,而是一个库?
如果它可以帮助我的程序,基本上是这样(解释)
(stdio and openssl headers here)
(debugging macro definitions here)
(two functions, gettime() and opensslrandom() defined here)
我似乎对宏也有理解的困难,因为它们最终将出现在共享库中,而它们在共享库中毫无用处? 我还把它们包含在libfoo.h中,尽管我还没有看到宏是否起作用。
您需要-c
gcc -fPIC -c libfoo.c
用于生成目标文件。
您可能需要看一下: http : //tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.