【问题标题】:C: compile some objects (for a shared library) without main() fails?C:在没有 main() 的情况下编译一些对象(对于共享库)失败?
【发布时间】:2011-03-27 03:36:31
【问题描述】:

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

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 中,尽管我还没有查看宏是否有效。

【问题讨论】:

    标签: c gcc shared-libraries


    【解决方案1】:

    你需要-c

    gcc -fPIC -c libfoo.c 
    

    用于生成目标文件。

    你可能想看看:http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

    【讨论】:

    • 太棒了,我知道有一些简单的东西!
    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 2016-04-17
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    相关资源
    最近更新 更多