【发布时间】:2020-02-16 18:58:36
【问题描述】:
这是我的 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
比在test文件夹里写了一个测试库的源代码(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)
请帮我解决这个问题。
【问题讨论】:
-
什么是
crt0.o?链接器找不到该文件。
标签: macos gcc linker static-libraries linker-flags