unable to link 2 object files and 1 header file to form an exe file.
Hi,
I am quite new to Dev C++ programming. At present, i am doing an assignment on classes. I have write 3 program named ops.cpp, sum.cpp and ops.h. I have include these 3 file into a project. All 3 file has been successfully compile individually. But when I try to compile the file sum.cpp which will depends on ops.cpp and ops.h, it fail to link ( I think ) . The error is shown below ( copy from compiler failure message :
C:\Dev-Cpp\Chapter 8 - tryout\Makefile.win [Build Error] ["Executable] Error 1
Would anyone please help me out ? My individual progrm has already compile successsfully.
The make file generated by dev c++ is shown below :
# Project: Project isolation classes
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = "Object\ file\ output/sum.o" "Object\ file\ output/ops.o" $(RES)
LINKOBJ = "Object\ file\ output/sum.o" "Object\ file\ output/ops.o" $(RES)
LIBS = -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/libexec"
INCS = -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include assignment"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include assignment" -I"C:/Dev-Cpp/mingw32/include" -I"C:/Dev-Cpp/mingw32/include/c++/3.4.5" -I"C:/Dev-Cpp/mingw32/include/c++/3.4.5/mingw32/bits" -I"C:/Dev-Cpp/mingw32/include/c++/3.4.5/ext" -I"C:/Dev-Cpp/mingw32/include/c++/3.4.5/debug" -I"C:/Dev-Cpp/mingw32/include/c++/3.4.5/bits" -I"C:/Dev-Cpp/mingw32/include/c++/3.4.5/backward" -I"C:/Dev-Cpp/mingw32/include/ddk" -I"C:/Dev-Cpp/mingw32/include/gcj" -I"C:/Dev-Cpp/mingw32/include/GL" -I"C:/Dev-Cpp/mingw32/include/gnu/awt/j2d" -I"C:/Dev-Cpp/mingw32/include/gnu/awt" -I"C:/Dev-Cpp/mingw32/include/gnu/classpath" -I"C:/Dev-Cpp/mingw32/include/gnu/gcj/convert" -I"C:/Dev-Cpp/mingw32/include/gnu/gcj/io" -I"C:/Dev-Cpp/mingw32/include/gnu/gcj/runtime" -I"C:/Dev-Cpp/mingw32/include/gnu/gcj" -I"C:/Dev-Cpp/mingw32/include/gnu/java/awt/image" -I"C:/Dev-Cpp/mingw32/include/gnu/java/awt/peer" -I"C:/Dev-Cpp/mingw32/include/gnu/java/awt" -I"C:/Dev-Cpp/mingw32/include/sys" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include assignment"
BIN = "Executable file output/Project isolation classes.exe"
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before "Executable file output/Project isolation classes.exe" all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "Executable file output\Project isolation classes.exe" $(LIBS)
"Object\ file\ output/sum.o": D:/Kean\ Fatt\ Document\ 1/C-plus-plus\ assignment/Chapter\ 8\ -\ Harnessing\ Polymorphism/Object\ file\ for\ Chapter\ 8\ -\ Isolating\ class\ structure/sum.cpp
$(CPP) -c "D:/Kean Fatt Document 1/C-plus-plus assignment/Chapter 8 - Harnessing Polymorphism/Object file for Chapter 8 - Isolating class structure/sum.cpp" -o "Object file output/sum.o" $(CXXFLAGS)
"Object\ file\ output/ops.o": D:/Kean\ Fatt\ Document\ 1/C-plus-plus\ assignment/Chapter\ 8\ -\ Harnessing\ Polymorphism/Object\ file\ for\ Chapter\ 8\ -\ Isolating\ class\ structure/ops.cpp
$(CPP) -c "D:/Kean Fatt Document 1/C-plus-plus assignment/Chapter 8 - Harnessing Polymorphism/Object file for Chapter 8 - Isolating class structure/ops.cpp" -o "Object file output/ops.o" $(CXXFLAGS)
I have no idea what does the makefile.win about because it does not state any error in my program.
Also below is my program for your reference :
ops.cpp
#include "ops.h" // Reference header file
#include <iostream>
using namespace std ;
Calculator::Calculator()
{ status = true ; } // Initialize status.
void Calculator::launch() // Display instructions.
{
cout << endl << "***SUM CALCULATOR***" << endl ;
cout << "Enter a number, an operator(+,-,*,/), and another number." << endl << "Hit return to calculate. Enter zero to exit." << endl ;
}
void Calculator::readInput() // Get expression.
{
cout << ">" ; cin >> num1 ; // Get 1st number.
if( num1 == 0 ) status = false ; // Exit if it's zero.
else { cin >> oper ; cin >> num2 ; } // Or get the rest.
}
void Calculator::writeOutput() // Display result.
{
if ( status ) switch ( oper ) // If continuing.
{
case '+' : { cout << (num1 + num2) << endl ; break ; }
case '-' : { cout << (num1 - num2) << endl ; break ; }
case '*' : { cout << (num1 * num2) << endl ; break ; }
case '/' : if( num2 != 0 )
cout << (num1 / num2) << endl ;
else
cout << "Cannot divide by zero" << endl ;
}
}
bool Calculator::run() // Get the current status.
{ return status ; }
sum.cpp
#include "ops.h"
#include <iostream>
using namespace std ;
int main()
{
int Hold_Screen ;
Calculator *pCalc = new Calculator ;
pCalc -> launch() ;
// this is to read instrcutions and write results
while ( pCalc -> run() )
{
pCalc -> readInput() ;
pCalc -> writeOutput() ;
}
cout << "Please input an integer: " ;
cin >> Hold_Screen ;
return 0 ;
}
ops.h
class Calculator
{
public:
Calculator() ; // (Constructor) To set initial status
void launch() ; // To display initial instructions.
void readInput() ; // To get expression.
void writeOutput() ; // To display results.
bool run() ; // (Accessor) To get current status.
private:
double num1, num2 ; // To store input numbers.
char oper ; // To store input operator.
bool status ; // To store current status.
} ;
Thank you. Anyone, Please guide me through. Your effort is greatly appreciated.
Thanks,
KF
First, source tags are your friend. Second, stop using Dev-C++ (and pay attention to the alternatives mentioned, namely Visual Studio and Code::Blocks, they're infinitely better). When you've tried to rebuild the program in either Visual Studio or Code::Blocks, post back here with your results.
Thank you MikeTacular. I will try out your suggestion and post it here after I have done. Thank you :-)
Best Regards,
KF
Best Regards,
KF
Quote:Original post by KF
Thank you MikeTacular. I will try out your suggestion and post it here after I have done. Thank you :-)
Best Regards,
KF
Sounds good [smile]. One thing you should notice immediately is that Code::Blocks and Visual Studio are not at all like Dev-C++. They can both be pretty intimidating at first (just because it's a new environment; not because it's hard or anything), so don't be afraid to come back and ask for help if you get stuck or lost along the way. Personally, I'd recommend Visual Studio since you're on a Windows machine (it's debugger is the bomb), but both work just fine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement