gpt4 book ai didi

c - 如何使用带有 '-static' 的 gcc 命令

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

当我尝试使用 gcc 命令编译带有静态库 't1' 的测试程序时,该静态库由我自己归档。

我用来归档静态库的命令是这样的:

ar rcv libt1.a t1.o

使用以下命令出现错误:

gcc -L. -static -lt1 t.c -o t

ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

但是,如果我像这样删除“-static”:

gcc -L. -lt1 t.c -o t

编译成功。我得到了正确的结果。

但我搜索了很多,发现其他人使用“-static”,他们没有得到错误。所以,请帮我算一下。

最佳答案

如评论中所述,-static 不需要链接到您的静态库,但用于指示编译器静态链接到 C(和 C++,如果g++) 运行时库。这is not supported在 OS X 上(链接取自上面的 linked answer),因此出现错误。

要链接到您的静态库,只需像在第二个命令行中那样操作,无需指定 -static

But I search a lot, find out other guys use '-static', and they do not get an error. So, please help me figure that.

他们可能在 Linux 或 Windows 上工作,其中支持针对 libc 的静态链接(尽管即使在 Linux 上它也带来了相当多的问题)。

关于c - 如何使用带有 '-static' 的 gcc 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36169528/

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