Complilation issues.

S

samoukos

Hello,
I am a high school student doing a project for a competition that I
took part to. Here is my code for a backtracking algorithm to find the
path through a minefield. I have include a sample of the input file.
When I compile it on my laptop(running Ubuntu 7.10 64-bit with GCC
4.1) using the comand "c++" everything compiles and works okay.
But the people from the competition told me that I must compile my
program using the following command "gcc -Wall -pipe -static -include /
usr/include/stdlib.h program.cpp". When I try to compile it using that
command I get a lot of errors. Which I have included.

Can anyone please explain what is happening and how I can fix it?
Thank you,
Sam Johnson


HERE IS THE CODE

//#include<stdio.h>
#include<fstream>
#include<iostream>
#include<cstdlib>
using std::ifstream
using std::eek:fstream;
using std::endl;
using std::ios;
using namespace std;

int xmax,ymax,narkes,xnark,ynark; //Used when reading input file
int xenter,yenter,xout,yout; //Used when reading input file

int cnt;
int field[UCHAR_MAX][UCHAR_MAX]={0}; //Array- holds mine field
int Route[UCHAR_MAX][3]={0}; //Array- holds route info Y1-
x, Y2-> y, Y3-> junc
int counter; //Counts number of steps
int path; //Debugging Stuff
//int xstep,ystep; //X, Y - coordinates for navigating the field
int i, j; //"For-Loop" Counters
void RecordRoute(int step, int xvalue, int yvalue);
void OutputField ();
//void NoWayOut(ofstream fout2);
int FindThePath(int counter, int xstep, int ystep, int xrange, int
yrange, int xexit, int yexit);
int FindJunction(int max);
ifstream fin;
ofstream fout;

int main ()
{
//=Open the Files=================================================
fin.open ("sab1.in");
fout.open("out.txt");
//=Read in Field Dimensions, # of Mines, Mine Locations, and Start/
Stop===============
fin >> xmax >> ymax;
fin >> narkes;
for (i=0;i<narkes;i++)
{
fin >> xnark >> ynark;
field[xnark][ynark]= 6;
}
fin >>xenter>>yenter;
fin >>xout>>yout;
field[xout][yout]=9;

OutputField(); //Debugging Only!!!
//=Find the Path=================================================
//=This finds one path through the mine field- not necessarily===
//=the shortest path. The path is written to array Route and cnt=
//=holds the number of steps taken to finish.====================
cnt=FindThePath(1, xenter, yenter, xmax, ymax, xout, yout);
bool Finished=false;
while (!Finished)
{
/* hmm just a thought
if (cnt>=1) && (cnt >= shortest)
{
cnt=FindThePath(FindJunction(cnt),Route[FindJunction(cnt)]
[1],Route[FindJunction(cnt)][2],xmax,ymax,xout,yout);
else hmm*/ if ((Route[cnt][1]==xout) && (Route[cnt][2]==yout))
{
Finished = true;
//=Output the Route and
Values==========================================
fout<<"Step X,Y Value"<<endl;
for (i=1;i<cnt+1;i++)
{
fout<<i<<" "<<Route[1]<<","<<Route[2]<<" "<<Route
[3]<<endl;
}
//=Output the Route and
Values==========================================
}
else if (FindJunction(cnt)>=1)
{
cout<<"Returning from "<<cnt<<endl; //Debugging Only!
cout <<"Returning to "<<FindJunction(cnt)<<endl; //Debugging Only!
cnt=FindThePath(FindJunction(cnt),Route[FindJunction(cnt)]
[1],Route[FindJunction(cnt)][2],xmax,ymax,xout,yout);
}
else
{
Finished = true;
fout<<0<<endl;
cout<<"No Way Out"<<endl; //Debugging Only!
}
}
//=Output the Path to the
File===========================================
//=Debugging Only!
for (j=1;j<=ymax;j++)
{
for (i=1;i<=xmax;i++)
fout << field[j]<< " ";
fout << endl;
}
//=Close the Files===================================================
fin.close();
fout.close();
return 0;
}
//Function Declarations

void RecordRoute(int step, int xvalue, int yvalue)
{
Route[step][1]=xvalue;
Route[step][2]=yvalue;
Route[step][3]= field[xvalue][yvalue];
}
void OutputField() //debugging
{
ofstream fout1;
fout1.open("field.txt"); //Field before it's traveled- debugging only!
for (j=1;j<=ymax;j++)
{
for (i=1;i<=xmax;i++)
{fout1 << field[j]<< " ";}
fout1 << endl;
}
fout1 << "======================================"<<endl;
fout1.close();
}
/*void NoWayOut(ofstream fout2)
{
fout2 <<0<<endl;
}
*/
int FindJunction(int max)
{
int hold, GoTo;
bool Found;
Found=false;
hold=max;
while (!Found)
{
if (Route[max][3]==3)
{
Found=true;
GoTo=max;
}
else if (max==1)
{
Found=true;
GoTo=-1;
}
max=max-1;
}
return GoTo;
}
int FindThePath(int counter, int xstep, int ystep, int xrange, int
yrange, int xexit, int yexit)
{

bool Safe=false;
bool Stuck=false;
while ((!Safe) && (!Stuck))
if ((field[xstep+1][ystep] == 9)||(field[xstep-1][ystep]==9)||
(field[xstep][ystep+1]==9))
{
field[xstep][ystep]=1;
RecordRoute(counter,xstep,ystep);
counter++;
RecordRoute(counter,xexit,yexit);
Safe=true;
}
//x-1 free, x+1 free and y+1 free
else if ((xstep+1<=xrange)&&(ystep+1<=yrange)&&(field[xstep-1]
[ystep]==0)&&(field[xstep+1][ystep]==0) && (field[xstep][ystep+1]==0))
{
field[xstep][ystep]=3;
RecordRoute(counter,xstep,ystep);
counter++;
xstep=xstep+1;
path=1;

cout<<path<<endl;
}
//x+1 free and y+1 free
else if ((ystep+1<=yrange)&&(field[xstep+1][ystep]==0) && (field[xstep]
[ystep+1]==0))
{
field[xstep][ystep]=3;
RecordRoute(counter,xstep,ystep);
counter++;
xstep=xstep+1;
path=28;
cout<<path<<endl;
}
//x-1 free and y+1 free
else if ((ystep+1<=yrange)&&(field[xstep-1][ystep]==0) && (field[xstep]
[ystep+1]==0))
{
field[xstep][ystep]=3;
RecordRoute(counter,xstep,ystep);
counter++;
ystep=ystep+1;
path=2;
cout<<path<<endl;
}
//x-1 free and x+1 free
else if ((xstep+1<=xrange)&&(xstep>1)&&(field[xstep-1][ystep]==0) &&
(field[xstep+1][ystep]==0))
{
field[xstep][ystep]=3;
RecordRoute(counter,xstep,ystep);
counter++;
xstep=xstep+1;
path=3;
cout<<path<<endl;
}
//x+1 only
else if ((xstep+1<=xrange)&&(field[xstep+1][ystep]==0))
{
field[xstep][ystep]=1;
RecordRoute(counter,xstep,ystep);
counter++;
xstep=xstep+1;
path=4;
cout <<path<<endl;
}
//y+1 only
else if ((ystep+1<=yrange)&&(field[xstep][ystep+1]==0))
{
field[xstep][ystep]=1;
RecordRoute(counter,xstep,ystep);
counter++;
ystep=ystep+1;
path=5;
cout <<path<<endl;
}
//x-1 only
else if ((xstep>1)&&(field[xstep-1][ystep]==0))
{
field[xstep][ystep]=1;
RecordRoute(counter,xstep,ystep);
counter++;
xstep=xstep-1;
path=6;
cout <<path<<endl;
}
else
{
cout << "We be stuck!"<<endl;
field[xstep][ystep]=5;
Stuck=true;
counter++;
}
return counter;
}

HERE
IS THE INPUT FILE

5 7
16
4 1
5 1
1 2
2 2
4 2
1 3
4 3
5 3
5 5
1 6
3 6
3 2
5 6
1 7
2 7
3 7
1 1
4 7

AND HERE ARE
THE ERRORS

sclean.cpp:17: warning: missing braces around initializer for 'int
[255]'
sclean.cpp:18: warning: missing braces around initializer for 'int
[3]'
/tmp/ccGUlQ2v.o: In function `__tcf_2':
sclean.cpp:(.text+0xfc): undefined reference to
`std::basic_ofstream said:
::~basic_ofstream()'
/tmp/ccGUlQ2v.o: In function `__tcf_1':
sclean.cpp:(.text+0x114): undefined reference to
`std::basic_ifstream said:
::~basic_ifstream()'
ield()':
sclean.cpp:(.text+0x869): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream()'
sclean.cpp:(.text+0x88b): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::eek:pen(char const*,
std::_Ios_Openmode)'
sclean.cpp:(.text+0x8d8): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:peraor<<(int)'
sclean.cpp:(.text+0x8e5): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0x910): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0x915): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0x949): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0x951): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0x956): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0x962): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::close()'
sclean.cpp:(.text+0x96e): undefined reference to
`std::basic_ofstream said:
::~basic_ofstream()'
sclean.cpp:(.text+0x98a): undefined reference to
`std::basic_ofstream said:
::~basic_ofstream()'
/tmp/ccUlQ2v.o: In function `main':
sclean.cpp:(.text+0x9e1): undefined reference to
`std::basic_ifstream<char, std::char_traits<char> >::eek:pen(char const*,
std::_Ios_Openmode)'
sclean.cpp:(.text+0xa01): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::eek:pen(char const*,
std::_Ios_Openmode)'
sclean.cpp:(.text+0xa10): undefined reference to
`std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
sclean.cpp:(.text+0xa1d): undefined reference to
`std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
sclean.pp:(.text+0xa2c): undefined reference to
`std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
sclea.cpp:(.text+0xa47): undefined reference to
`std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
sclean.cpp:(.text+0xa54): undefined reference to
`std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
/tmp/ccGUlQ2v.o:sclean.cpp:(.text+0xaac): more undefined references to
`std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
follow
/tmp/ccGUlQ2v.o: In function `main':
sclean.cpp:(.text+0xbb9): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xbc1): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xbc6): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xc3b): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xc48): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xc52): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
scleancpp:(.text+0xc5f): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xc6a): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xc77): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xc82): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xc8a): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xc8f): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xce2): undefined reference to `std::cout'
sclean.cpp:(.text+0xce7): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xcf1): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xcf9): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xcfe): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xd15): undefined reference to `std::cout'
sclean.cpp:(.text+0xd1a): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xd24): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xd2c): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xd31): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xdd1): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xdd9): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xdde): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xde8): undefined reference to `std::cout'
sclean.cpp:(.text+0xded): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xdf5): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xdfa): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xe54): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
sclean.cpp:(.text+0xe61): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
sclean.cpp:(.text+0xe85): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&)'
sclean.cpp:(.text+0xe8f): undefined reference to
`std::basic_ostream said:
::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))'
sclean.cpp:(.text+0xebc): undefined reference to
`std::basic_ifstream<char, std::char_traits<char> >::close()'
sclean.cpp:(.text+0xec6): undefined reference to
`std::basic_ofstream<char, std::char_traits<char> >::close()'
/tmp/ccGUlQ2v.o:(.eh_frame+0x13): undefined reference to
`__gxx_personality_v0'ollect2: ld returned 1 exit status
 
I

Ioannis Vranos

samoukos said:
Hello,
I am a high school student doing a project for a competition that I
took part to. Here is my code for a backtracking algorithm to find the
path through a minefield. I have include a sample of the input file.
When I compile it on my laptop(running Ubuntu 7.10 64-bit with GCC
4.1) using the comand "c++" everything compiles and works okay.
But the people from the competition told me that I must compile my
program using the following command "gcc -Wall -pipe -static -include /
usr/include/stdlib.h program.cpp". When I try to compile it using that
command I get a lot of errors. Which I have included.

Can anyone please explain what is happening and how I can fix it?
Thank you,
Sam Johnson


"gcc" is used for compiling C programs. g++ is used for compiling C++
programs. Are you sure the competition is not about C, and is about C++?
 
S

samoukos

"gcc" is used for compiling C programs. g++ is used for compiling C++
programs. Are you sure the competition is not about C, and is about C++?

Well they said at the official website that they wanted the students
to use either C or C++...And i chose c++..
I see you are greek..so am i..i took part at the competition that is
happeing in greece...see the site www.pdp.gr
maybe you may find something i did not...
 
I

Ioannis Vranos

samoukos said:
Well they said at the official website that they wanted the students
to use either C or C++...And i chose c++..
I see you are greek..so am i..i took part at the competition that is
happeing in greece...see the site www.pdp.gr
maybe you may find something i did not...


OK, it looks like you came across some "irrelevant" persons.


If your code is 100% ISO C++ compliant it should compile with

g++ -ansi -pedantic-errors -Wall file1.cpp [...] filen.cpp -o Program_Name
 
S

samoukos

yes i compiled ur code and yes u need g++ compiler not gcc.

works great here!

thank you...that was kinda stupid...i should have though that gcc is
for C and and g++ for C++..thanks for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top