Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:27:28+00:00 2026-06-12T06:27:28+00:00

I am a CS student learning how to program in C. I have 3

  • 0

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:

  • Undefined Reference to a function
  • "Undefined reference to function" error

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:27:29+00:00Added an answer on June 12, 2026 at 6:27 am

    First of all, separate definitions from declarations:

    logic.h:

    #ifndef _LOGIC_H_
    #define _LOGIC_H_
    
    /* Define BIT as before */
    
    int adder(int O1, int O2,  BIT carryIn, BIT *carryOut);
    BIT full_adder(BIT A, BIT B, BIT Ci, BIT *Co);
    
    
    #endif
    

    logic.c:

    #include <stdio.h>
    #include "logic.h"
    
    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
      if((A==FALSE)&&(B==FALSE)&&(Ci==FALSE)){
        S=FALSE;
        *Co = FALSE;
      }
    
      return S;
    }
    

    main.c:

    #include "logic.h"
    
    int main(int argc, char* argv[]) {
      /* Do your stuff */
      return 0;
    }
    

    Now things are where they should be and your logic.h supplies the needed information to the compiler.

    Your makefile should not need any fancy stuff with only these three files.

    This needs to be done via the makefile:

    gcc -c -o main.o main.c
    gcc -c -o logic.o logic.c
    gcc -o main main.o logic.o
    

    (The logical problems that you have in your full_adder are left for your to solve…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A student in my class brought this to my attention, and I didn't have
I'm a university student learning programming. For practice I'm writing a blackjack program. I'm
I am a student trying to use some of the machine learning algorithms for
I'm a student, and for my next job, I have to program a module
I am a co-op student learning vb.net and I have a project which retrieves
I just started learning Free Pascal and I wrote this fairly basic program to
I'm learning JQuery. I'm a new Jquery Student as it is seen. This is
I'm a student just learning xml and c#. I'm writing a program that will
I'm a student learning PHP. I basically make the stuff work, but never wondered
I am a student learning C++, and I am trying to understand how null-terminated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.