c++compilationsolaris

Compilation of mutiple files in c++ solaris


I have three simple files:

Header file for a class

> cat myhh.hh
#include<iostream>

class helloworld
{
string str;
public:
void start(string &);
void stop(string &);
};

its corresponding cc file

> cat myhh.cc
#include<iostream>
#include "myhh.hh"
using namespace std;

void helloworld::start(string &str1)
{
  cout<< ""function started"<<endl;
}
void helloworld::stop(string &str2)
{
cout<< ""function stopped"<<endl;
}

Now the main function:

> cat mymain.cc 
#include<iostream>

#include "myhh.hh" 

int main()
{

helloworld obj;
obj.start(std::string("XXXX"));
obj.stop(std::string("XXXX"));


}
>

My primary intension is to generate a.out with these 3 files and when i execute it it should print:

function started
function stopped

i tried to compile but i am getting below errors.

> CC mymain.cc
Undefined                       first referenced
 symbol                             in file
void helloworld::stop(std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) mymain.o
void helloworld::start(std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) mymain.o
ld: fatal: Symbol referencing errors. No output written to a.out
> 

I am sure i am not getting the basics right.but its just i am trying to learn things of compilation process. Could anybody please help?


Solution

  • You need to compile myhh.cc and link generated object as well

    $CC -c myhh.cc -o myhh.o
    $CC -o mymain mymain.cc myhh.o