【发布时间】:2012-07-28 22:56:03
【问题描述】:
我有两个文件 -> /home/snyp1/new 文件夹中的 fact.h 和 main.c。 main.c 具有调用fact.h 中的fact(int x) 函数的主函数。我正在使用 ar 命令创建 .a 存档 ->
snyp1@Snyp:~/new$ ar -r -s libfact.a fact.o
ar: creating libfact.a
fact.h fact.o libfact.a main.c
snyp1@Snyp:~/new$ gcc main.c -L/home/snyp1/new -lfact -o main
/home/snyp1/new/libfact.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status
snyp1@Snyp:~/new$ ranlib libfact.a
snyp1@Snyp:~/new$ gcc main.c -L/home/snyp1/new -lfact -o main
/home/snyp1/new/libfact.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status
我在 ubuntu 12.04 上。请让我知道有什么问题。 (另外,如果我不使用-L/.../new,gcc 会说它找不到“lfact”,可能是因为它不在/usr/local/lib 中)
编辑:好的,我找到了原因。这是因为我使用fact.h 构建fact.o 然后将其放入库中,它没有按预期工作。所以我现在把它改成了file.c,现在工作正常。我应该提供这些信息,对不起。虽然我不知道为什么会出现这种问题。如果没有至少一个.c 文件,就不能创建库吗?
【问题讨论】:
标签: gcc static-libraries unix-ar