静态库gcc - 找不到库

时间:2017-03-14 21:16:19

标签: makefile static-libraries gnu-make

我想创建静态库并出现问题。我有makefile:

static: main.c tree.c
    gcc -c -Wall tree.c -o tree.o
    ar crs libtree.a tree.o
    gcc -Wall -static main.c -L. -ltree -o main
    ./main

当我写“make static”时,它会告诉我:

gcc -c -Wall tree.c -o tree.o
ar crs libtree.a tree.o
gcc -Wall -static main.c -L. -ltree -o main
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [static] Error 1

它创建了文件:tree.o和libtree.a。我不知道为什么它不想找到一个图书馆。你知道怎么解决吗?

1 个答案:

答案 0 :(得分:0)

最有可能的是,您的系统未设置为静态链接。大多数较新的Linux发行版都不是因为非常不鼓励使用静态链接。

查找名为glibc-static或类似的软件包并安装。

如果你的系统不是Linux(也可能是MacOS X,你没有说明) - 你注定要失败。该平台根本不支持静态链接。

相关问题