C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old April 25th, 2008, 12:18 PM
amd0freak amd0freak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 amd0freak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 21 sec
Reputation Power: 0
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;
}

Reply With Quote
  #2  
Old May 6th, 2008, 04:33 AM
MaHuJa MaHuJa is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2007
Posts: 338 MaHuJa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 13 m 10 sec
Reputation Power: 1
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
Quote:
I won't include the header file,

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.

Reply With Quote
  #3  
Old May 6th, 2008, 04:54 AM
amd0freak amd0freak is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 amd0freak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 21 sec
Reputation Power: 0
i found out i was trying to run object code. oops. no sleep in a week does that to you.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - Exec format error. Wrong Architecture.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway