PDA

View Full Version : Xcode Error




sari210
Jun 15, 2009, 11:31 AM
I keep getting this error when I try to run a program I have written in Xcode. I know the problem works because my co-worker can get it to run on his PC. Any help you can offer is greatly appreciated.

This is the error:

Command/Developer/usr/bin/g++-4.0 failed with exit code 1


Thank you!!



garethlewis2
Jun 15, 2009, 12:00 PM
Might be useful if you actually supply the command line you are using. All that tells me is that gcc failed.

gnasher729
Jun 15, 2009, 12:04 PM
I keep getting this error when I try to run a program I have written in Xcode. I know the problem works because my co-worker can get it to run on his PC. Any help you can offer is greatly appreciated.

This is the error:

Command/Developer/usr/bin/g++-4.0 failed with exit code 1


Thank you!!

Command/Developer/usr/bin/g++-4.0 failed with exit code 1 is not the error. It is what XCode says whenever _anything_ goes wrong, so there is no information here whatsoever.

Any compiler error messages, or linker error messages?

sari210
Jun 15, 2009, 12:19 PM
My guess it is a linker error message. But what do I do to fix it seeing it worked on Dev C++ from my friend?


Here is the full error message:

Linking/Users/sjahnke2008/C++/particles_in_ring/build/Debug/particles_in_ring.app/Contents/MacOS/particles_in_ring (1 error)

duplicate symbol TApplication::Init(__CFString const*, __CFString const*)in /Users/sjahnke2008/C++/particles_in_ring/build/particles_in_ring.build/Debug/particles_in_ring.build/Objects-normal/i386/TApplication-8969F669.o and /Users/sjahnke2008/C++/particles_in_ring/build/particles_in_ring.build/Debug/particles_in_ring.build/Objects-normal/i386/TApplication-8969F669.o

Sander
Jun 15, 2009, 02:58 PM
Sounds like one source file is added to the project twice..? Or there really are two Init() methods in one source file, which makes it strange that it does work on your colleague's machine.

garethlewis2
Jun 15, 2009, 03:29 PM
Dump the code of the project, or zip it up and post it. I can't tell you based upon that linker message.

sari210
Jun 17, 2009, 04:09 PM
So Here is the code, I just copied and pasted it. If there is a better way to do this let me know. The code isn't 100% complete. I don't have it outputting the data yet or have it linked with the random number generator I want to use. Maybe that is the problem. I don't know. Thanks everyone for your help.

//
// The purpose of this program is to find the probabilities
// that Number of Particles will exist in the nth Spaces of
// the ring lattice with nNumberofSpaces
//
//

#include <Carbon/Carbon.h>
#include "TApplication.h"
#include "TWindow.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

double ran2();

int main()
{
int* Ring;
int* Location;
int numberOfSpaces = 0, numberOfParticles = 0, monteCarlo = 0, choice = 0;
char programEnd = 'R';
double alpha = 0, success = 0;
srand(time(0));

do
{
cout << "Enter the Number of Spaces in the Ring:" ;
cin >> numberOfSpaces;

cout << "Enter the number of particles: ";
cin >> numberOfParticles;

cout << "Choose a number, up to one decimal place to be alpha,\n"
<< "the rate at which the particles can move:";
cin >> alpha;

cout << "Enter the number of steps that you want the process to complete:";
cin >> monteCarlo;

// Creates Ring
Ring = new int[numberOfSpaces];
for(int i = 0; i < numberOfSpaces; i++)
{
Ring[i] = 0;
}

//Places particles in the ring
for (int i = 1; i == numberOfParticles; i++)
{
Ring[i-1] = i;
}

//Stores Particle Placement on the Ring
Location = new int[numberOfParticles + 1];
for(int i = 0; i == numberOfParticles; i++)
{
Location[i] = i-1;
}

//Runs the MonteCarlo Steps
for (int i = 0; i < monteCarlo; i++)
{
for (int i2 = 0; i2 < numberOfParticles; i2++)
{
choice = random() % numberOfParticles + 1;
if (Location[choice] != (Location[choice + 1] - 1))
{
success = random() % 100 + 1;
if(alpha >= success)
{
Ring[Location[choice] + 1] = choice;
Ring[Location[choice]] = 0;
Location[choice]++;
if (Location[choice] = numberOfSpaces - 1)
{
Location[choice] = 0;
}
}
}
}
}
cout << "Program is Finished. Enter R to rerun:" ;
cin >> ProgramEnd;
delete [] Ring;
Ring = NULL;
}
while ((rrogramEnd == 'R') || (programEnd == 'r'));
return 0;
}

double ran2()
{
int RandomNumber = 0;
RandomNumber = rand();
return RandomNumber;
}

gnasher729
Jun 17, 2009, 04:20 PM
I'd start fresh with a new project, starting with "New Project" -> "Command Line Tool" -> "C++ Tool", and not "Application" -> "Carbon C++ Application".

gnasher729
Jun 17, 2009, 06:44 PM
//Places particles in the ring
for (int i = 1; i == numberOfParticles; i++)
{
Ring[i-1] = i;
}


Finding out yourself what this bit of your code does should be very educational.

sari210
Jun 18, 2009, 11:31 AM
I'd start fresh with a new project, starting with "New Project" -> "Command Line Tool" -> "C++ Tool", and not "Application" -> "Carbon C++ Application".

So just that alone made a world of difference. After walking through my code with someone who is far better at C++ than I, I was able to get my program fixed. Thanks!

P.S. I ended up fixing that other stuff too.