Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined reference to function called 'full_adder(BIT A, BIT B, BIT Ci, BIT *Co)'
    primarykey
    data
    text
    <p>I am a CS student learning how to program in C. I have 3 files and a Makefile. I have</p> <blockquote> <p>logic.c logic.h main.c </p> </blockquote> <p>the top of logic.c is:</p> <pre><code> #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 &lt;br&gt; if((A==FALSE)&amp;&amp;(B==FALSE)&amp;&amp;(Ci==FALSE)){ S=FALSE; *Co = FALSE; } &lt;br&gt; return S; } </code></pre> <p>the top of main.c is:</p> <pre><code> #include "logic.h" BIT full_adder(BIT A, BIT B, BIT Ci, BIT *Co); </code></pre> <p>in main.c I have my main function, at the bottom of main function I have : </p> <pre><code> assert((full_adder(FALSE,FALSE,FALSE,&amp;Co)==FALSE) &amp;&amp; (Co==FALSE)); adder(FALSE,FALSE,FALSE,&amp;Co2); return 0; </code></pre> <p>I am getting the error: </p> <pre><code> main.o: In function 'main': main.c:158: undefined referenceto 'full_adder' collect2: ld returned 1 exit status &lt;br&gt; make: *** [pa3] Error 1 &lt;br&gt; ./bscript: line 3: pa3: command not found </code></pre> <p>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.</p> <p>The questions that did not answer my question were:</p> <ul> <li><a href="https://stackoverflow.com/questions/6423340/undefined-reference-to-a-function">Undefined Reference to a function</a></li> <li><a href="https://stackoverflow.com/questions/11277344/undefined-reference-to-function-error">&quot;Undefined reference to function&quot; error</a></li> </ul> <p>Any help is appreciated.</p> <p>EDIT: logic.c is getting compiled and it does create a logic.o file.</p> <p>EDIT: my prof says that I cannot edit logic.h</p> <p>EDIT: makefile: </p> <pre><code># 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) $&lt; @echo "" # Clean up the directory clean: @echo "Cleaning up project directory ..." rm -f *.o $(EXE) core a.out @echo "" </code></pre> <p>EDIT: I compile my code with the script:</p> <pre><code>#!/usr/bin/sh make pa3 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload