gpt4 book ai didi

c - 如何用静态库编译gcc?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:16 25 4
gpt4 key购买 nike

我有静态库 lib.a 并且在所有教程中都使用:

gcc -o main main.o -L. -lib

但是我不能,我有错误:

    /usr/bin/ld: cannot find -lib
collect2: error: ld returned 1 exit status

我需要使用:

gcc -o main main.o -L. -lib.a

为什么?我应该怎么做才能修复它?

最佳答案

来自 gcc -l 的文档:

-llibrary:

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

...

The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.

因此您不能将 -l 与名为“lib.a”的库一起使用。使用不带 -l 的“lib.a”来包含它。当然,您不能使用 -L 然后设置要搜索该特定库的目录。

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

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