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

  • Home
  • SEARCH
  • 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 7408341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:53:55+00:00 2026-05-29T05:53:55+00:00

I’m new to C++, switching over from Java for a class I’m taking in

  • 0

I’m new to C++, switching over from Java for a class I’m taking in college. In our first assignment we have to write several makefiles for our code. My first makefile isn’t working – it always complains about an error in “TempControlTest: undefined reference to ‘BangBangControl::XXXX’, where XXXX a function in BangBangControl (I get errors for every function in BangBangControl). I’ve been looking around online and all the makefile examples look slightly different so I can’t tell what I’m doing wrong. I’ll post all my code below, if anyone could just give me a little help, that would be AWESOME. Also, this is due tonight, so any quick help is appreciated so much. If you’re still here, thanks very much!

HeatingUnit.h:

#ifndef HEATINGUNIT_H
#define HEATINGUNIT_H

class HeatingUnit {

private:
        bool on;
        int temp;

public:
        HeatingUnit(bool o, int t);
        void turnOn();
        void turnOff();
        int tick();
};

#endif

HeatingUnit.cpp:

#include "HeatingUnit.h"

HeatingUnit::HeatingUnit(bool o, int t) {
        on = o;
        temp = t;
}

void HeatingUnit::turnOn() {
        on = true;
}

void HeatingUnit::turnOff() {
        on = false;
}

int HeatingUnit::tick() {
        if(on) return ++temp + 1;
        else return --temp;
}

BangBangControl.h:

#ifndef BANGBANGCONTROL_H
#define BANGBANGCONTROL_H

#include "HeatingUnit.h"

class BangBangControl {

private:
        int tempToKeep;
        HeatingUnit unit;

public:
        BangBangControl(int ttk, bool on, int initTemp);
        void setTemp(int t);
        int getTemp();
        void update();
};

#endif

BangBangControl.cpp:

#include "HeatingUnit.h"
#include "BangBangControl.h"

BangBangControl::BangBangControl(int ttk, bool on, int initTemp) 
: unit(on, initTemp) {
        tempToKeep = ttk;
}

void BangBangControl::setTemp(int t) {
        tempToKeep = t;
}

int BangBangControl::getTemp() {
        return tempToKeep;
}

void BangBangControl::update() {
        int currentTemp = unit.tick();
        if(currentTemp > tempToKeep + 2) unit.turnOff();

        else if(currentTemp < tempToKeep - 2) unit.turnOn();
}

TempControlTest.cpp:

include <iostream>
#include "BangBangControl.h"
using namespace std;

int main() {
        BangBangControl bang(100, false, 60);
        for(int i = 0; i < 50; i++) {
                bang.update();
                cout << bang.getTemp() << " ";
                if(i % 10 == 9) cout << endl;
        }
}

And finally, Makefile_Executable:

all: TempControlTest

TempControlTest: TempControlTest.cpp BangBangControl.o
        g++ -o TempControlTest TempControlTest.cpp

BangBangControl.o: BangBangControl.cpp HeatingUnit.o
        g++ -c BangBangControl.cpp

HeatingUnit.o: HeatingUnit.cpp
        g++ -c HeatingUnit.cpp

clean:
        rm -rf *.o TempControlTest

Again, thank you very much!

  • 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-05-29T05:53:56+00:00Added an answer on May 29, 2026 at 5:53 am

    You aren’t linking your objects together.

    You’ve got two lines compiling BangBangControl.cpp and HeatingUnit.cpp to two .o files (although I doubt you need to have BangBangControl.o depend on HeatingUnit.o). But you need to put them together into the final executable (this is called “linking”).

    TempControlTest: TempControlTest.cpp BangBangControl.o HeatingUnit.o
            g++ -o TempControlTest TempControlTest.cpp HeatingUnit.o BangBangControl.o
    

    In the line above, TempControlTest.cpp will be itself compiled, and then linked together with the two already-compiled objects on which it seems to depend into one executable.

    NB: when you get an “Undefined reference” error, it generally means your code compiles fine but was missing a symbol it needed to be linked against.

    NB2: your makefile rules don’t cause the cpp files to depend on the headers they use. That means when you change a header and run “make”, make will tell you everything’s already built. That’s bad.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.