在 mac OS 上使用 gcc 编译代码时,链接器无法链接自定义静态库

while compiling a code using gcc on mac OS linker failed in linking custom made static library

这是我的项目文件的 C 语言文件结构:
首先是一个完整的课程文件夹
fullCourse 文件夹包含三个文件夹:
1.包括
2. 源码
3. 库
4. 测试
在包含文件夹中:
它包含一个头文件:temp.h

temp.h 的代码如下:

#ifndef __$__temp_h
#define __$__temp_h 234
int yash();
#endif

在 src 文件夹中:
它包含一个源文件:temp.c

temp.cc 的代码如下:

#ifndef __$__temp_c
#define __$__temp_c 234
int yash()
{
return 22;
}
#endif

然后留在同一个文件夹中,创建 .o 文件如下:

gcc -I ../include -c temp.c

下一步是将此 temp.o 文件移动到 lib 文件夹,如下所示:

mv temp.o ../lib

比留在 lib 文件夹中创建的存档(或库)文件如下:

ar rcs libtmds.a temp.o

比在测试文件夹中写了一个测试库的源代码(tempTest.c)
tempTest.c 的代码如下:

#include<stdio.h>
#include<temp.h>
int main()
{
int w;
w=yash();
printf("%d\n",w);
return 0;
}

比留在测试文件夹中尝试按如下方式编译它:

gcc -static -I ../include tempTest.c -L ../lib -ltmds -o tempTest.exe

但代码未编译,显示以下错误:

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

请帮我解决这个问题。

-static这里是错误的。 link 到你的静态库只是简单的 link 到它没有任何 -static 标志,这是用于内核编译。