I am using a solaris machine to run my c++ code

I have written the following code in the mentioned files

classclock.h

#include <iostream>
using namespace std;
class classclock
{
    private: 

     	int min;
        int hour;
        int sec;
     	//member function for the operations
	public:
	void SetTime(int a,int b,int c);
};

classclock.cc

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

void classclock::SetTime(int a,int b,int c)
{
	if (0 < a && a < 24)
	{
		hour = a;
	}
	else {
	    hour = 0;
	}
	if (0 < b && a < 60)
	{
		min = b;
	}
	else {
	    min =0;
	}

	if (0 < c && c < 60)
	{
		sec = c;
	}
	else {
	    sec = 0;
	}
}

test.cc

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


int main(){

	classclock myclock;
	myclock.SetTime(10,10,10);
        return 0;
}

I am not able to compile my test.cc and I am getting the following error:

Undefined first referenced
symbol in file
classclock::SetTime(int, int, int) /var/tmp//ccrMIpwv.o

ld: fatal: Symbol referencing errors. No output written to test
collect2: ld returned 1 exit status

please help!!!

Recommended Answers

All 9 Replies

It does compiles when I move my main function inside the classclock.cc file, I believe this is because there was no main function in this .cc file, but this just compiles the code and it gives me run time error as below: please help!

using: Command not found.
: Command not found.
: Command not found.
: Command not found.
Badly placed ()'s.

You have 2 C++ files, test.cc and classclock.cc

The problem you highlighted in post 1 is at the link stage and is because you have compiled and linked test.cc maybe like this

g++ test.cc

what you need to do is compile test.cc, compile classclock.cc and link the output of the 2 compilations together because test.cc is referencing functions defined in classclock.cc

You might be able to do it something like

g++ -Wall -pedantic test.cc classclock.cc

@Bafna : yeah it did compile this time but it gives me the following run time error:

using: Command not found.
: Command not found.
: Command not found.
: Command not found.
Badly placed ()'s.

That does not look like a likely runtime error from the code you have posted.

Perhaps you had better post the command line you are using.

prompt: g++ -Wall -pedantic test.cc classclock.cc
prompt: ./test.cc
using: Command not found.
: Command not found.
: Command not found.
: Command not found.
Badly placed ()'s.

You do not invoke the output of your program with

./test.cc

That is you source file.

The output will be a.out so you would use

./a.out

as you command line

Got it!
Thanks a ton for bearing with my dumb questions :-D

In g++ -Wall -pedantic test.cc classclock.cc

What does -Wall and -pedantic options stand for?
And also as I am new to this system can you please refer me a link where I can learn more about these options?

I really appreciate your time and effort.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.