C:在没有 main() 的情况下编译一些对象(对于共享库)失败?
据我所知,我需要按照此步骤准备制作共享库:
gcc -fPIC libfoo.c -o libfoo.o
然后链接它。我曾尝试制作一个 makefile 来帮助完成这些步骤,但现在似乎出现了错误。
当我运行 make 文件时会发生这种情况:
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
如何在没有 main 函数的情况下编译库文件,因为它不是程序而是旨在成为库?
如果它对我的程序有帮助,基本上是这样的(解释的)
(stdio and openssl headers here)
(debugging macro definitions here)
(two functions, gettime() and opensslrandom() defined here)
我似乎在理解宏方面也有问题,因为它们最终会在共享库中,它们在共享库中毫无用处?我将它们包含在 libfoo.h 中,尽管我还没有看到这些宏是否有效。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要
-c
来生成目标文件。
您可能需要查看: http://tldp.org/HOWTO/程序库-HOWTO/shared-libraries.html
You need
-c
for generating the object files.
You may want to look at: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html