| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
General - Exec format error. Wrong Architecture.
I made a ComplexNumber class.
ComplexNumber.cpp compiles just fine, along with its included ComplexNumber.h whenever I try to run ComplexNumber.o, I get this error before any execution of the program!!! " Exec format error. Wrong Architecture." I have searched the web and the only thing I found is if you used a compiler or compiled in a way that is not executable by the OS.... all I did was, in Red Hat Enterprise 5 g++ -c ComplexNumber.cpp chmod u-x ComplexNumber.o ComplexNumber.o and my code LOOKS fine...I mean it did compile without error... I won't include the header file, all the prototypes line up with the implementation so you guys know what it looks like from this ComplexNumber.cpp Code:
#include "ComplexNumber.h"
#include <iostream>
#include <string>
using namespace std;
// constructors
ComplexNumber::ComplexNumber()
{
real=0;imag=0;
}
ComplexNumber::ComplexNumber(double real_part, double imaginary_part)
{
real=real_part; imag=imaginary_part;
}
ComplexNumber::ComplexNumber(const ComplexNumber & rhs)
{
this->real=rhs.real; this->imag=rhs.imag;
}
// named member functions
void ComplexNumber::print(ostream & out) const
{
out << this->real;
if(this->imag > 0) {out << " + ";} {out << " ";}
out << this->imag << "i";
}
bool ComplexNumber::equals(const ComplexNumber & rhs) const
{
return (real==rhs.real && imag==rhs.imag);
}
const ComplexNumber & ComplexNumber::operator= (const ComplexNumber & rhs)
{
real=rhs.real; imag=rhs.imag;
}
const ComplexNumber & ComplexNumber::operator+= (const ComplexNumber & rhs)
{
this->real=this->real+rhs.real;
this->imag=this->imag+rhs.imag;
}
const ComplexNumber & ComplexNumber::operator-= (const ComplexNumber & rhs)
{
this->real=this->real-rhs.real;
this->imag=this->imag-rhs.imag;
}
const ComplexNumber & ComplexNumber::operator*= (const ComplexNumber & rhs)
{
this->real = (this->real * rhs.real) - (this->imag * rhs.imag);
this->imag = (this->real * rhs.imag) + (this->imag * rhs.real);
}
// arithmetic operators
ComplexNumber operator+(const ComplexNumber & lhs, const ComplexNumber & rhs)
{
//ComplexNumber *result = new ComplexNumber(lhs);
ComplexNumber result;
result+=rhs;
result+=lhs;
return result;
}
ComplexNumber operator-(const ComplexNumber & lhs, const ComplexNumber & rhs)
{
ComplexNumber result;
result+=lhs;
result-=rhs;
return result;
}
ComplexNumber operator*(const ComplexNumber & lhs, const ComplexNumber & rhs)
{ //(A + Bi) * (C + Di) = (A*C - B*D) + (A*D + B*C)i
//ComplexNumber *result = new ComplexNumber();
ComplexNumber result;
result+=lhs;
result*=rhs;
return result;
}
// relational operators
bool operator==(const ComplexNumber & lhs, const ComplexNumber & rhs)
{
return lhs.equals(rhs);
}
bool operator!=(const ComplexNumber & lhs, const ComplexNumber & rhs)
{
return !lhs.equals(rhs);
}
// I/O operators
ostream & operator<<(ostream & out, const ComplexNumber & n)
{
n.print(out);
return out;
}
istream & operator>>(istream & in, ComplexNumber & n)
{
string input; char *trash; double d; double e; char **useless_ptr;
in >> input;
d = strtod(strtok((char*)input.c_str(), " "),useless_ptr);
trash = strtok(NULL, " +-");
delete trash;
e = strtod(strtok(NULL, "\0"),useless_ptr);
ComplexNumber ptr;
ptr = ComplexNumber(d,e);
n=ptr;
//const ComplexNumber &p=new ComplexNumber(d,e);
//n = p;
//n.operator=(ptr);
return in;
}
int main()
{
/*Your main function should read in two complex numbers (using the overloaded input operator),
use the overloaded operators to compute the following results (in this order), displaying the
results at each step (using the overloaded output operator):
* C1 + C2
* C1 - C2
* C1 * C2
* C1 == C2
* C1 != C2
* C1 += C2 (then reset C1 to its original value)
* C1 -= C2 (then reset C1 to its original value)
* C1 *= C2
An example of how your main function should run and the output it should produce is given below:
Enter a complex number C1:
4.2 + 8.3i
Enter a complex number C2:
3.1 - 9.2i
For C1 = 4.2 + 8.3i and C2 = 3.1 - 9.2i :
C1 + C2 = 7.3 - 0.9i
C1 - C2 = 1.1 + 17.5i
C1 * C2 = 89.38 - 12.91i
C1 == C2 is false
C1 != C2 is true
After C1 += C2, C1 = 7.3 - 0.9i
After C1 -= C2, C1 = 1.1 + 17.5i
After C1 *= C2, C1 = 89.38 - 12.91i
You may assume that the user will always enter both the real and the imaginary parts of a complex
number. For example, the user will enter "5 + 0i" (and not "5") or "0 - 6.2i" (and not "-6.2i").*/
//ComplexNumber *a = new ComplexNumber(); ComplexNumber *b = new ComplexNumber();
ComplexNumber a;
ComplexNumber b;
cout <<"Enter a complex number C1:";
cin >>a;
cout <<"Enter a complex number C2:";
cin >>b;
cout <<"For C1 = "<< a <<" and C2 = "<< b << ":\n";
ComplexNumber c= a + b;
cout <<"C1 + C2 = "<< c << "\n";
c = a - b;
cout <<"C1 - C2 = "<< c << "\n";
c = a * b;
cout <<"C1 * C2 = "<< c << "\n";
cout <<"C1 == C2 is ";
if(a==b) {cout << "true\n";} else {cout << "false\n";}
cout <<"C1 != C2 is ";
if(a!=b) {cout << "true\n";} else {cout << "false\n";}
c = a; a += b;
cout <<"After C1 += C2 = "<< a << "\n";
a = c;
a -= b;
cout <<"After C1 -= C2 = "<< a << "\n";
a = c;
a *= b;
cout <<"After C1 *= C2 = "<< a << "\n";
return 0;
}
|
|
#2
|
|||
|
|||
|
Quote:
While we may indeed be able to find out what it would say, it would be quicker to look at it. Anyway, if it compiles fine but you get that error, that's likely irrelevant to your problem. First of all, the cpu type compiled for must match the cpu the machine is running on - this is rarely a problem. I suspect the compiler, in the absense of better instructions, produced an output file in the a.out format; this format is considered obsolete (there is a better word, but I don't remember it) and one should instead use the ELF format. You can compile support for a.out executables into the kernel, but figuring out how to make the result in the ELF format might be a better path. If that file was the result of running only the compiler on it, how about letting a linker get a look at it, even though it is only one file? Just a guess. |
|
#3
|
|||
|
|||
|
i found out i was trying to run object code. oops. no sleep in a week does that to you.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > General - Exec format error. Wrong Architecture. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|