Hi guys!

I wrote a class "Complex" which is representing complex numbers. Nevermind, I was trying to make it a library so i could use it easily in other projects but when i compiled i always got this an error. This is the log from the compilation.

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\samuel\My Documents\Cpp\New Folder\Makefile.win"
Executing make clean
rm -f Complex.o Project1.a

g++.exe -c Complex.cpp -o Complex.o -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" -fexceptions

ar r Project1.a Complex.o

ar: creating Project1.a

ranlib Project1.a

Execution terminated

Here are also the source files first the header then the source,

#ifndef COMPLEX_H
#define COMPLEX_H

#include "math.h"
class Complex{
public:
Complex(): x(0),y(0){}
Complex(double real, double imaginary){x = real; y = imaginary;}

Complex operator+(Complex &C_nr2);
Complex operator-(Complex &C_nr2);
Complex operator*(Complex &C_nr2);
double Real(){ return x;}
void Real (double real){ x = real;}

double Imag(){return y;}
void Imag (double imaginary){y = imaginary;}

double Abs();
double Abs2();

private:
double x, y;

};

#endif
#include "Complex.h"

Complex Complex::operator+(Complex &C_nr2){

Complex sum(C_nr2.Real() + x, C_nr2.Imag()+y);
return sum;

}
//------------------------------------------------------------------------------
Complex Complex::operator-(Complex &C_nr2){

Complex diff( x - C_nr2.Real(), y - C_nr2.Imag() );
return diff;
//------------------------------------------------------------------------------
}

Complex Complex::operator*(Complex &C_nr2){
double im, real;
real = x*C_nr2.Real() - y*C_nr2.Imag();
im = x*C_nr2.Imag() + y*C_nr2.Real();
Complex prod(real , im);
return prod;

}
//------------------------------------------------------------------------------
double Complex::Abs(){
return sqrt(x*x+y*y);
}

double Complex::Abs2(){

return x*x+y*y;
}

Oh and I tried using the library file which came out from the compilation but it didnt work in any project. I linked to the library file and included the header but i didnt work.

Thanx for helping

Sam

2
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by samush

oh I forgot!
I'm using Dev Bloodshed 4.9.9.2
:P

What do you mean "it didn't work" ? Do you take your car to the repair shop and tell the repairman "it doesn't work" ? You have to be a lot more descriptive of the problem, and post an example project.

ok! I make it simple here is the project:

#include <cstdlib>
#include <iostream>

#include "Complex.h"
using namespace std;

int main(int argc, char *argv[])
{
Complex c(1,2);
system("PAUSE");
return EXIT_SUCCESS;
}

I have linked to the library file which was created from the files in my first post. I did this in project options under parameters. When compiling the project above i get these errors:

3 C:\Dev-Cpp\include\c++\3.4.2\backward\Complex.h:31, from main.cpp In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/Complex.h:31, from main.cpp

3 C:\Documents and Settings\samuel\My Documents\Cpp\testpro\main.cpp from main.cpp

32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

And some others but these are the first ones.

Thanx for helping!!

I compiled and did not receive those warnings. Attached are my project files for both the lib and test program, with *.o and *.exe files removed.

Ok now I see my mistake... I didn't have the library file in the same directory as the project. When i put it in the same directory then there wasn't any problem.
But what do you do if you don't want to move the library file? How do you link to it?

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.