好吧,我正在制作一个可以实现每种形式的数据结构的程序堆栈。并为每个文件创建单独的文件,现在我想在单个驱动程序程序中使用每个单独的文件。我已经将文件链接为:
#include"filename.c"
但是出现错误 no这样的文件或目录。是的。 您不包括 假设您的文件夹包含您的 现在,在 确保编译您使用的每个来源,它将确保正确链接所有内容: 这是一种非常基本的方法,那里还有更多 - 甚至可能比这更好 - 但它可以完成工作。 确保查看.c
文件,而不是.h
文件。main.c
文件和datastructs.c
文件,请创建一个包含所有函数声明的datastructs.h
文件。datastructs.c
#include <stdio.h>
#include "datastructs.h"
void hello() {
printf("hello, world!n");
}
datastructs.h
void hello();
main.c
中 - 包含main
函数的C文件 - 包括datastructs.h
文件并调用您想要的所有功能:#include "datastructs.h"
void main() {
hello();
}
gcc datastructs.c main.c -o main
Makefile
和make
的工作原理,这样您就可以更好地处理此类任务。