小编Van*_*Van的帖子

C中的分层链接

我想以分层方式链接三个文件.

// a.c
int fun1(){...}
int fun2(){...}

// b.c
extern int parameter;
int fun3(){...//using parameter here}

// main.c
int parameter = 1;
int main(){...// use fun1 fun2 fun3}
Run Code Online (Sandbox Code Playgroud)

所以,我先将三个文件分别编译成目标文件a.o,b.o然后main.o.然后我想结合a.ob.o进入另一个目标文件tools.o.并最终使用tools.omain.o生成可执行文件.

但是,当我尝试结合a.ob.o喜欢时ld -o tools.o a.o b.o,链接器说undefined reference to 'parameter'.我怎么能将这些目标文件链接到一个中间目标文件?

c linker compiler-errors

2
推荐指数
1
解决办法
64
查看次数

标签 统计

c ×1

compiler-errors ×1

linker ×1