I am a CS student learning how to program in C. I have 3 files and a Makefile. I have
logic.c logic.h main.c
the top of logic.c is:
#include "logic.h"
//use this function in 4 bit adder
//BIT full_adder(BIT A, BIT B, BIT Ci, BIT *Co);
int adder(int O1, int O2, BIT carryIn, BIT *carryOut){
printf("in adder");
return 0x0;
}
BIT full_adder(BIT A, BIT B, BIT Ci, BIT *Co){
BIT S = FALSE;
//implementation of if else's based on Truth Table <br>
if((A==FALSE)&&(B==FALSE)&&(Ci==FALSE)){
S=FALSE;
*Co = FALSE;
} <br>
return S;
}
the top of main.c is:
#include "logic.h"
BIT full_adder(BIT A, BIT B, BIT Ci, BIT *Co);
in main.c I have my main function, at the bottom of main function I have :
assert((full_adder(FALSE,FALSE,FALSE,&Co)==FALSE) && (Co==FALSE));
adder(FALSE,FALSE,FALSE,&Co2);
return 0;
I am getting the error:
main.o: In function 'main': main.c:158: undefined referenceto 'full_adder'
collect2: ld returned 1 exit status <br>
make: *** [pa3] Error 1 <br>
./bscript: line 3: pa3: command not found
This is homework, but I have spent a good deal of time on this problem and am looking for some help. I have the correct return type for adder, full_adder, and I declare the function in the top of both logic.c and main.c.
The questions that did not answer my question were:
Any help is appreciated.
EDIT: logic.c is getting compiled and it does create a logic.o file.
EDIT: my prof says that I cannot edit logic.h
EDIT: makefile:
# Makefile template for CS 270 (specialized for PA3)
# List of files
C_SRCS = main.c logic.c
C_OBJS = main.o logic.o
C_HEADERS = logic.h
OBJS = ${C_OBJS}
EXE = pa3
# Compiler and loader commands and flags
GCC = gcc
GCC_FLAGS = -g -std=c99 -Wall -O0 -c
LD_FLAGS = -g -std=c99 -Wall -O0
# Target is the executable
pa3 : $(OBJS)
@echo "Linking all object modules ..."
$(GCC) $(LD_FLAGS) $(OBJS) -o $(EXE)
@echo ""
# Recompile C objects if headers change
${C_OBJS}: ${C_HEADERS}
# Compile .c files to .o files
.c.o:
@echo "Compiling each C source file separately ..."
$(GCC) $(GCC_FLAGS) $<
@echo ""
# Clean up the directory
clean:
@echo "Cleaning up project directory ..."
rm -f *.o $(EXE) core a.out
@echo ""
EDIT: I compile my code with the script:
#!/usr/bin/sh
make
pa3