0

I'm reading this one book on c++ and am having difficulty making an executable.
I'm a n00b at c++ and Ubuntu
so I don't know what I'm doing wrong.
I've compiled all my cpp files into object files and now I need to link it
but when I try that I get this:

uncle@Orion:~/Desktop/gamedev/calc$ g++ -o calculator *.o -lm
main.o: In function `main':
main.cpp: (.text+0x28d): undefined reference to `SAMSErrorHandling::Initialize()'
main.cpp: (.text+0x33a): undefined reference to `SAMSErrorHandling::HandleRuntimeError(std::runtime_error)'
main.cpp: (.text+0x3c2): undefined reference to `SAMSErrorHandling::HandleNotANumberError()'
main.cpp: (.text+0x3f7): undefined reference to `SAMSPrompt::UserWantsToContinueYOrN(char const*)'
collect2: ld returned 1 exit status

any suggestions?
also header files... um... I've made them, am I supposed to link those somehow too?:confused:

Edited by thetechguy: n/a

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by thetechguy
0

Show us the code?

o ok I just attached them.

Attachments
#include <iostream>
#include <stdexcept>
#include "ErrorHandlingModule.h"

using namespace std;

namespace SAMSErrorHandling
{
	using namespace std;
	
	void Inititalize(void)
	{
		cin.exceptions(cin.failbit);
	}
	
	int HandleNotAnumberError(void) //Returns error code
	{
		cerr << "Input error - not a number?" << endl;
		cin.clear();
		//Eat the bad input so we can pause the program
		char BadInput[5];
		cin >> BadInput;
		return 1; // An error occured
	}
	int HandleRuntimeError(runtime_error theRuntimeError)
		{
			cerr << theRuntimeError.what() << endl;
			return 1;
		}
}
#include <iostream>
#include <stdexcept>
#include "PromptModule.h"
#include "ErrorHandlingModule.h"

using namespace std;

char GetOperator(void)
{
	char theOperator;
	cout << "Operator: ";
	cin >> theOperator;
	return theOperator;
}

float GetOperand(void)
{
	float theOperand = 1;
	cout << "The Operand: ";
	cin >> theOperand;
	return theOperand;
}
	
	



float Accumulate (const char theOperator,const float theOperand)
	{
		static float myAccumulator = 0; //Inititalize to 0 when the program starts
		switch (theOperator)
		{
			case '+':
				myAccumulator = myAccumulator + theOperand;
				break;

			case '-':
				myAccumulator = myAccumulator - theOperand;
				break;
			case '*':
				myAccumulator = myAccumulator * theOperand;
				break;
			case '/':
				myAccumulator = myAccumulator / theOperand;
				break;
			default:
				throw
					runtime_error("Error - Invalid Operator");
		};
	return myAccumulator;
	}





int main(int argc, char* argv[])
{
	SAMSErrorHandling::Initialize();
	do
	{
		try
		{
			char Operator = GetOperator();
			float Operand = GetOperand();
			cout << Accumulate(Operator,Operand) << endl;
		}
		catch (runtime_error RuntimeError)
		{
			SAMSErrorHandling::HandleRuntimeError(RuntimeError);
		}
		catch (...)
		{
			SAMSErrorHandling::HandleNotANumberError();
		};
	}
	while (SAMSPrompt::UserWantsToContinueYOrN("More ?"));
	return 0;
}
#include <iostream>
#include "PromptModule.h"

using namespace std;

namespace SAMSPrompt
{

void PauseForUserAcknowledgement(void)
{
	//Note: You must type something before Enter
	char StopCharacter;
	cout << endl << "Press a key and \"Enter\": ";
	cin >> StopCharacter;
}

bool UserWantstoContinueYOrN (const char *theThingWeAreDoing)
	{
		char DoneCharacter;
		bool InvalidCharacterWasEntered = false;
		do
		{
			cout << endl << theThingWeAreDoing << " - Press \'n\' and \'Enter\' to stop: ";
			cin >> DoneCharacter;

			InvalidCharacterWasEntered = 
			!
			(
				(DoneCharacter == 'y')
				||
				(DoneCharacter == 'n')
			);

				if (InvalidCharacterWasEntered)
					{
						cout << "...Error - " << "please enter \"y\" or \"n\"."<<endl;
					};
		}while (InvalidCharacterWasEntered);
	return (DoneCharacter != 'n');

	}
}
0

the header files
in case I messed those up somehow

Attachments
#ifndef ErrorHandlingModuleH
#define ErrorHandlingModuleH
#include <stdexcept>

using namespace std;

namespace SAMSErrorHandling
{
	void Initialize(void);
	int HandleNotANumberError(void); //Returns error code
	int HandleRuntimeError(runtime_error theRuntimeError);
}

#endif
#ifndef PromptModuleH
#define PromptModuleH


namespace SAMSPrompt
{
void PauseForUserAcknowledgement(void);
bool UserWantsToContinueYOrN (const char *theThingWeAreDoing);
}
#endif
0

Just for trial, try putting :

using namespace SAMSErrorHandling;

at the top of your main.

tried that, compiled fine but still get the same message when I try to link
:'(
lol at your sig btw xD

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.