gpt4 book ai didi

c - 如何编译Discount C库?

转载 作者:太空宇宙 更新时间:2023-11-04 03:02:16 24 4
gpt4 key购买 nike

我想使用 Discount要转换的 C 库 Markdown将文本转换为 HTML。我已经成功编译并安装了库(版本 2.1.3)。

我试着编译这段代码

#include <mkdio.h>
int main(void)
{
FILE *in, *out;
MMIOT *doc;

in = fopen("sample.md", "r");
out = fopen("out.html", "w");

doc = mdk_in(in, 0);
markdown(doc, out, 0);

...
}

解释:mkd_in()将输入文件in读入库工作类型MMIOT doc并markdown() 应该将 doc 转换为 HTML 并将其写入 out 文件。

使用命令 gcc -Wall -lmarkdown -o FILE FILE.c 我总是得到以下输出:

undefined reference to `mkd_in(_IO_FILE*, unsigned int)'
undefined reference to `markdown(void*, _IO_FILE*, unsigned int)'

注意:我使用--shared选项运行Discount的配置工具来构建动态库。默认是一个静态库,但我遇到了同样的问题。

最佳答案

试试这个:

gcc -Wall -o FILE FILE.c -lmarkdown

-l 的位置很重要,因为许多链接器只会使用库来满足未解析的引用,如果它们存在-l 时已解析。 例如,这可能会导致循环依赖的各种问题。

在您最初拥有它的地方,这些函数并非未解析,因为您尚未编译 FILE.c。当您确实编译FILE.c 时,该点后面没有-l 来满足引用。

来自 gcc 手册页:

Order does matter when you use several options of the same kind; for example, if you specify -L more than once, the directories are searched in the order specified. Also, the placement of the -l option is significant.

然后,在 -l 下:

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

关于c - 如何编译Discount C库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10053785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com