编译时对subdir中的.o文件的未定义引用
我的项目体系结构:
project_folder/
|--bin/
|--src/
| |-----module1/
| | |----> module1.c
| | |----> module1.h
| | |----> module1.o
| | |----> makefile
| |-----module2/
| | |----> module2.c
| | |----> module2.h
| | |----> module2.o
| | |----> makefile
|-- makefile
|-- main.c
当我完成项目时,它会正确构建项目的模块,然后当我想编译整个项目时,我对模块功能的参考不确定。
我认为错误来自我脑海中的CC命令,所以这是我的makefile:
export CC = gcc
PACKAGES = module1 module2
MAIN = main.c
EXEC = bin
all: $(PACKAGES) $(EXEC)
$(PACKAGES):
@$(MAKE) $(MAKECMDGOALS) -C $@
$(EXEC): $(MAIN)
$(CC) $(MAIN) -o $(EXEC)
.PHONY: all clean $(PACKAGES)
clean: $(PACKAGES)
错误是:
/usr/bin/ld: /project_folder/main.c:line undefined reference to `module1_fct1`
有什么建议吗?
My project architecture :
project_folder/
|--bin/
|--src/
| |-----module1/
| | |----> module1.c
| | |----> module1.h
| | |----> module1.o
| | |----> makefile
| |-----module2/
| | |----> module2.c
| | |----> module2.h
| | |----> module2.o
| | |----> makefile
|-- makefile
|-- main.c
When I make my project It correctly builds the modules of my project and then when I want to compile the whole project I have undefined reference to modules' functions.
I think the error comes from my CC command in my head makefile so here is my makefile :
export CC = gcc
PACKAGES = module1 module2
MAIN = main.c
EXEC = bin
all: $(PACKAGES) $(EXEC)
$(PACKAGES):
@$(MAKE) $(MAKECMDGOALS) -C $@
$(EXEC): $(MAIN)
$(CC) $(MAIN) -o $(EXEC)
.PHONY: all clean $(PACKAGES)
clean: $(PACKAGES)
Error is :
/usr/bin/ld: /project_folder/main.c:line undefined reference to `module1_fct1`
Do y have any advice ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论