【发布时间】:2015-09-21 05:08:21
【问题描述】:
我在通过 Makefile 编译我的程序时遇到问题。 Ofcorse 我阅读了许多具有类似问题的主题,但我无法理解我的情况,因此我在编译时遇到问题。
这是我在 c 上编写的程序。简直就是。这不是全部内容,但我认为这足以理解 Makefile 中的问题。程序只有 3 个文件:
- main.c(包括 struct.h 并使用 struct.c 中的对象)
- 结构.h
- struct.c(包括 struct.h)
main.c
#include "struct.h"
#define SIZE_STRUCT 2
int main()
{
int i = 0;
while(i < 2)
{
printf("Contens %d /n" , CommandStructure[i].size)
i = i +1;
}
return 0;
}
还有 struct.h
#ifndef STRUCT
#define STRUCT
struct Command
{ char tableCmd[5];
char *NameCommand;
int size;
};
#endif
和struct.c
#include "struct.h"
static struct Command CommandStructure[]={
{
.tableCmd = {0x3,0x5,0x4,0x4,0x5},
.NameCommand = "SOMEWHERE",
.size = 11,
},{
.tableCmd = {0x6, 0x34, 0x40, 0x22, 0x4},
.NameCommand = "SOMETHING",
.size = 12,
}
};
还有我的主要问题 Makefile
NAME=test
all: main.c struct.c struct.h
gcc struct.c main.c -o $(HOME)/Pulpit/$(NAME)
当然我得到错误
错误:“CommandStructure”未声明(在此函数中首次使用) if(!strncmp(buf, CommandStructure[i].NameCommand, CommandStructure[i].size)) main.c:140:27: 注意:每个未声明的标识符只报告一次 它出现在 Makefile:6 中的函数:polecenia dla obiektu 'all' nie powiodły się make: *** [all] Error1
【问题讨论】:
-
你永远不会在 main.c 中定义 CommandStructure
-
@bmargulies its' 在 struct.c 文件中,不是吗?
-
致@OP,你知道你错过了
stdio.h吗?
标签: c struct makefile header-files