C:在没有 main() 的情况下编译一些对象(对于共享库)失败?

发布于 2024-10-26 15:23:07 字数 730 浏览 2 评论 0原文

据我所知,我需要按照此步骤准备制作共享库:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的夜不怕黑 2024-11-02 15:23:07

您需要 -c

gcc -fPIC -c libfoo.c 

来生成目标文件。

您可能需要查看: http://tldp.org/HOWTO/程序库-HOWTO/shared-libraries.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文