跑完后,
Cygwin-PC ~/code_practice/Computing/list
$ gcc -c arrayImpl.c -o arrayImpl.o
代码目录结构,在windows(cygwin)中
Cygwin-PC ~/code_practice/Computing/stack
$ ls
main.c stack.h stackImpl.c
Cygwin-PC ~/code_practice/Computing/list
$ ls
arrayImpl.c arrayImpl.o linkedListImpl.c list.h main.c
Stack
抽象取决于List
抽象,用于数据表示&的使用。
List
抽象如下所示,
/************ list.h ************/
/***************** Usage-start ************/
typedef enum{false, true}bool;
typedef enum {CREATE_NEW_LIST, DOUBLE_THE_LIST, HALF_THE_LIST}Op;
#if defined(ARRAY)
/* To ensure Encapsulation(i.e., maintain invariants of array) */
typedef struct List List;
#elif defined(LINKED_LIST)
/* To ensure Encapsulation(i.e., maintain invariants of linked list) */
/* User will not get access to node*/
typedef struct List List;
#else
#error "Wrong list implementation macro name !!!"
#endif
void insertItem(List *, void *newItem);
void *deleteItem(List *, int listIndex);
void *deleteLastItem(List *);
List* createList(List *, Op opType);
/***************** Usage-end ***************/
/***************** arrayImple.c **************/
#if defined(ARRAY)
#include"list.h"
/************ Representation - start ************/
typedef struct List{
void **array;
/* Following members for Housekeeping - Array enhancement*/
int lastItemPosition;
int size;
}List;
#define INITIAL_LIST_SIZE 50
/********************* Representation - end ************/
/************* Usage - start ***************/
List *createList(List *list, Op opType){
....
}
void insertItem(List *arrayList, void *newItem){
...
}
void *deleteItem(List *arrayList, int listIndex){
....
}
void * deleteLastItem(List *arrayList){
...
}
/******************** Usage - end *******************/
#endif
Stack
抽象,如下所示,
/********* stack.h *********/
#include"../list/list.h"
typedef struct Stack Stack;
Stack *createStack();
void push(Stack *, void *item);
void*pop(Stack *);
/*********** stackImpl.c *******/
#include"../list/list.h"
typedef struct Stack{
List *stack;
}Stack;
Stack* createStack(){
Stack *s = malloc(sizeof(Stack));
s->stack = createList((void *)0, CREATE_NEW_LIST);
return s;
}
void push(Stack *s, void *item){
insertItem(s->stack, item);
}
void *pop(Stack *s){
void *item = deleteLastItem(s->stack);
return item;
}
以下编译说明,以下给出的消息,不涉及链接器,
Cygwin-PC ~/code_practice/Computing/stack
$ gcc -c -DARRAY main.c stackImpl.c ../list/arrayImpl.o
gcc: warning: ../list/arrayImpl.o: linker input file unused because linking
not done
编译失败,给出以下错误,
Cygwin-PC ~/code_practice/Computing/stack
$ gcc -DARRAY main.c stackImpl.c ../list/arrayImpl.o
/tmp/ccapgYQI.o:stackImpl.c:(.text+0x25): undefined reference to
`createList'
/tmp/ccapgYQI.o:stackImpl.c:(.text+0x4b): undefined reference to
`insertItem'
/tmp/ccapgYQI.o:stackImpl.c:(.text+0x61): undefined reference to
`deleteLastItem'
collect2: error: ld returned 1 exit status
问题,
从上面的编译命令,为什么GNU链接器(ld
)不接受../list/arrayImpl.o
文件来查找createList()
,insertItem()
&的定义。 deleteLastItem()
编译工作,
Cygwin-PC ~/code_practice/Computing/stack
$ gcc -DARRAY main.c stackImpl.c ../list/arrayImpl.c
答案 0 :(得分:1)
gcc -c arrayImpl.c -o arrayImpl.o
缺少-DARRAY
。如果没有这个,arrayImpl.c
中的代码将被有条件删除:
/***************** arrayImple.c **************/
#if defined(ARRAY)
答案 1 :(得分:0)
此
=SUMIFS($B$1:$B$5,$A$1:$A$5,"<=" & A6,$C$1:$C$5,"<>OFF")
失败,因为你错过了arrayImpl.c
kaylum有正确的答案,当你编译arrayImpl.c时你忘了-DARRAY