Ido H Levi
Ido H Levi

Reputation: 166

undefined reference to 'func' error in makefile

I'm trying to pass references from one header file to my main file, when these functions are written in a different .c file, and I'm getting an undefined reference to 'fund' to all of these functions. In my main file I only have one include which is #include "Declerations.h" when #include "Declerations.h" code is:

#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

I'm not getting SymbolFuncs.c nor DecleratioFuncs.c functions, and getting the same error for both in Assembler.c. Another note, SymbolFuncs functions are declared in Symbols.h The output window part which the error is occurring:

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

Upvotes: 0

Views: 104

Answers (1)

Ctx
Ctx

Reputation: 18430

You see in your output:

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

The compiler flag -c is missing here, so it is trying to link, which of course fails.

However, according to the rules in your makefile that shouldn't happen. There is probably a second Makefile (with capital M, which has precedence over a makefile with lowecase m) with different rules. You should remove that.

Upvotes: 2

Related Questions