hi mcriscolo ,im sorry i actually misplaced 'ls' in the SOURCES and HEADERS path but later when i gave make command it showed some errors like this:
[root@localhost makedemo]# make
g++ -c -o /root/workspace/source/Main.o /root/workspace/source/Main.cpp
/root/workspace/source/Main.cpp:1:24: SourceData.H: No such file or directory
/root/workspace/source/Main.cpp:2:22: TestFile.H: No such file or directory
/root/workspace/source/Main.cpp: In function `int main()':
/root/workspace/source/Main.cpp:5: error: `TestFile' was not declared in this scope
/root/workspace/source/Main.cpp:5: error: expected `;' before "obj"
/root/workspace/source/Main.cpp:6: error: `SourceData' was not declared in this scope
/root/workspace/source/Main.cpp:6: error: expected `;' before "sd"
/root/workspace/source/Main.cpp:7: error: `sd' was not declared in this scope
/root/workspace/source/Main.cpp:9: error: `obj' was not declared in this scope
make: *** [/root/workspace/source/Main.o] Error 1
im sure i've no problem in other header and source files as i compiled and ran successfully when all was in the same folder(including makefile).
i've used makedepend tool for dependency and i think above problem is arising because of dependency issue.i would also like to know where(in which folder) .o files will be created when im compiling ?
any way i've also included source and header file coding here...
source:
Main.cpp:
#include "SourceData.H"
#include "TestFile.H"
int main()
{
TestFile obj;
SourceData sd;
sd.rollNum = 101;
sd.name = "Shiva";
obj.Display(sd);
return 0;
}
TestFile.cpp:
#include <iostream>
#include "TestFile.H"
void TestFile::Display(SourceData &d)
{
std::cout<<d.ToString()<<std::endl;
}
Header:
SourceData.H
#ifndef _SORCEDATA_H_
#define _SORCEDATA_H_
#include <iostream>
#include <sstream>
#include <string>
struct SourceData
{
int rollNum;
std::string name;
std::string ToString()
{
std::stringstream sst;
sst<<"RollNum = "<<rollNum<<"\n";
sst<<"Name = "<<name<<"\n";
return sst.str();
}
};
#endif
TestFile.H:
#ifndef _TESTF1_H_
#define _TESTF1_H_
#include "SourceData.H"
class TestFile
{
public:
void Display(SourceData &d);
};
#endif
and my makefile was like this:
HEADERS = $(shell ls/root/workspace/makedemo/header/ *.H)
SOURCES = $(shell ls/root/workspace/source/ *.cpp)
COMPILERFLAGS = -W -Wall
DEBUGFLAGS = -g
CPPCOMPILER = g++
INCLUDES = -I.
OBJS = $(SOURCES:.cpp=.o)
BINARY = output
all: $(BINARY)
$(BINARY): $(OBJS)
$(CPPCOMPILER) $(COMPILERFLAGS) $(INCLUDES) -o $(BINARY) $(OBJS)
depend:
makedepend -f- -- $(SOURCES) > .depend_file
clean:
rm -rf *.o .depend_file $(BINARY) *~
#DO NOT DELETE