从我学到的知识,我需要按照以下步骤来准备制作共享库:

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

关于C:在没有main()的情况下编译某些对象(用于共享库)会失败吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5447030/

10-11 22:11
查看更多