在makefile

时间:2018-08-18 12:10:55

标签: c makefile header undefined

当这些函数写在不同的.c文件中时,我试图将引用从一个头文件传递到我的主文件,并且对所有这些函数都使用undefined reference to 'fund'。 在我的主文件中,当#include "Declerations.h"代码为:

时,我只有一个include是#include "Declerations.h"
#ifndef Declerations_h
#define  Declerations_h
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Machine_Memory.h"
#include "Symbols.h"

#define MAX_LINE 1024
#define A 0
#define R 2
#define E 1
#define RIGHT_BIT 16384
#define BITS_IN_WORD 14

int is_a_op(char * wrd);
int find_op(char *wrd);
int op_group(int op);
int is_a_sign(char * wrd);
int is_new_line(char * wrd);
#endif

makefile:

assembler: Assembler.o DecleratioFuncs.o SymbolFuncs.o
    gcc -g -ansi -Wall -pedantic Assembler.o SymbolFuncs.o DecleratioFuncs.o -o assembler
Assembler.o: Assembler.c Declerations.h
    gcc -c -ansi -Wall -pedantic -o Assembler.o Assembler.c
SymbolFuncs.o: SymbolFuncs.c Declerations.h
    gcc -c -ansi -Wall -pedantic -o SymbolFuncs.o SymbolFuncs.c
DecleratioFuncs.o: DecleratioFuncs.c Declerations.h
    gcc -c -ansi -pedantic -Wall -o DecleratioFuncs.o DecleratioFuncs.c

我没有获得SymbolFuncs.cDecleratioFuncs.c函数,并且在Assembler.c中都没有得到相同的错误。 另请注意,SymbolFuncs函数在Symbols.h中声明 发生错误的输出窗口部分:

student@ubuntu:~/Desktop/Finished_Project$ make
gcc -ansi -Wall -pedantic -o Assembler.o Assembler.c
Assembler.c: In function ‘main’:
Assembler.c:28:2: warning: ISO C90 forbids mixed declarations and code [-pedantic]
Assembler.c:243:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat]
Assembler.c:268:6: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat]
Assembler.c:317:9: warning: value computed is not used [-Wunused-value]
Assembler.c:342:9: warning: value computed is not used [-Wunused-value]
Assembler.c:376:19: warning: comparison with string literal results in unspecified behavior [-Waddress]
Assembler.c:392:8: warning: value computed is not used [-Wunused-value]
Assembler.c:424:8: warning: value computed is not used [-Wunused-value]
Assembler.c:447:9: warning: value computed is not used [-Wunused-value]
Assembler.c:464:9: warning: value computed is not used [-Wunused-value]
Assembler.c:500:8: warning: value computed is not used [-Wunused-value]
Assembler.c:548:8: warning: value computed is not used [-Wunused-value]
Assembler.c:581:8: warning: value computed is not used [-Wunused-value]
Assembler.c:602:9: warning: value computed is not used [-Wunused-value]
Assembler.c:648:8: warning: value computed is not used [-Wunused-value]
Assembler.c:58:37: warning: unused variable ‘entry_list’ [-Wunused-variable]
Assembler.c:58:16: warning: unused variable ‘extern_list’ [-Wunused-variable]
Assembler.c:51:18: warning: unused variable ‘num_to_add’ [-Wunused-variable]
Assembler.c:46:6: warning: variable ‘L’ set but not used [-Wunused-but-set-variable]
Assembler.c:42:6: warning: unused variable ‘ise’ [-Wunused-variable]
Assembler.c:33:33: warning: unused variable ‘next’ [-Wunused-variable]
Assembler.c:33:17: warning: unused variable ‘memory’ [-Wunused-variable]
Assembler.c: In function ‘add_to_mem’:
Assembler.c:757:2: warning: ISO C90 forbids mixed declarations and code [-pedantic]
Assembler.c:767:2: warning: ISO C90 forbids mixed declarations and code [-pedantic]
Assembler.c:767:6: warning: unused variable ‘val’ [-Wunused-variable]
/tmp/ccdCytpY.o: In function `main':
Assembler.c:(.text+0x171): undefined reference to `is_new_line'
Assembler.c:(.text+0x18c): undefined reference to `is_a_sign'
Assembler.c:(.text+0x278): undefined reference to `add_to_slist'
Assembler.c:(.text+0x785): undefined reference to `find_op'
Assembler.c:(.text+0x853): undefined reference to `op_group'
Assembler.c:(.text+0x897): undefined reference to `is_a_sign'
Assembler.c:(.text+0x981): undefined reference to `is_a_sign'
Assembler.c:(.text+0xa88): undefined reference to `op_group'
Assembler.c:(.text+0xc2a): undefined reference to `is_a_sign'
Assembler.c:(.text+0xcc9): undefined reference to `is_a_sign'
Assembler.c:(.text+0x103d): undefined reference to `is_a_sign'
Assembler.c:(.text+0x109b): undefined reference to `op_group'
Assembler.c:(.text+0x11e2): undefined reference to `is_a_sign'
Assembler.c:(.text+0x14c3): undefined reference to `is_a_sign'
Assembler.c:(.text+0x16dc): undefined reference to `find_address'
collect2: ld returned 1 exit status
make: *** [Assembler.o] Error 1

1 个答案:

答案 0 :(得分:2)

您在输出中看到:

gcc -ansi -Wall -pedantic -o Assembler.o Assembler.c

此处缺少编译器标志-c,因此它正在尝试链接,当然会失败。

但是,根据makefile中的规则,不应发生这种情况。可能还有第二个Makefile(大写的M,优先于小写m的makefile),它们具有不同的规则。您应该删除它。