By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

compilation problem (port cpp from windows)

P: n/a
I have a small program to read data from some data files , in it I use
string types to build the data file name but when I try to compile it I
get: (see code below error)
root@rob-laptop:/home/rob/pankaj# gcc ptcllocate.cpp
/tmp/ccg9j6Mi.o: In function `main':ptcllocate.cpp:(.text+0x99):
undefined reference to `std::allocator<char>::allocator()'
:ptcllocate.cpp:(.text+0xb9): undefined reference to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
>::basic_string(char const*, std::allocator<charconst&)'
:ptcllocate.cpp:(.text+0xc7): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0xd5): undefined reference to
`std::allocator<char>::allocator()'
:ptcllocate.cpp:(.text+0xf5): undefined reference to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
>::basic_string(char const*, std::allocator<charconst&)'
:ptcllocate.cpp:(.text+0x111): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x133): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x141): undefined reference to
`std::allocator<char>::allocator()'
:ptcllocate.cpp:(.text+0x161): undefined reference to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
>::basic_string(char const*, std::allocator<charconst&)'
:ptcllocate.cpp:(.text+0x17d): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x196): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x1d6): undefined reference to
`std::allocator<char>::~allocator()'


any Idea what I am missing?
code:
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>

int main(int argc,char *argv[])
{
using namespace std;
int i,j;
long double
x[19500],y[19500],z[19500],c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,m1,m2,m3,m 4,m5,m6,m7,m8,m9,m10,m11,m12,a=0,b=0,c=0,f=0,k;
long double l, m, n, o ;

string beginning = "count";
string endding = ".txt";
string outf = "data";
string cf1(beginning + argv[0] + endding);
string cf2(beginning + argv[1] + endding);
string cf3(beginning + argv[2] + endding);
string cf4(beginning + argv[3] + endding);
string cf5(beginning + argv[4] + endding);
string cf6(beginning + argv[5] + endding);
string cf7(beginning + argv[6] + endding);
string cf8(beginning + argv[7] + endding);
string cf9(beginning + argv[8] + endding);
string cf10(beginning + argv[9] + endding);
string cf11(beginning + argv[10] + endding);
string cf12(beginning + argv[11] + endding);
string of1(outf + argv[1] + "_" + argv[11] + endding);
ifstream in1(cf1.c_str());
ifstream in2(cf2.c_str());
ifstream in3(cf3.c_str());
ifstream in4(cf4.c_str());
ifstream in5(cf5.c_str());
ifstream in6(cf6.c_str());
ifstream in7(cf7.c_str());
ifstream in8(cf8.c_str());
ifstream in9(cf9.c_str());
ifstream in10(cf10.c_str());
ifstream in11(cf11.c_str());
ifstream in12(cf12.c_str());
ifstream in13;
ifstream in14;
ifstream in15;
ifstream in16;
ifstream in17;
ifstream in18;
ifstream in19;
ifstream in20;
ifstream in21;
ifstream in22;
ifstream in23;
ifstream in24;

ofstream out_file;
out_file.open(of1.c_str());
while (!in1.eof())
{
in13.open("detector1.txt");
in14.open("detector2.txt");
in15.open("detector3.txt");
in16.open("detector4.txt");
in17.open("detector5.txt");
in18.open("detector6.txt");
in19.open("detector7.txt");
in20.open("detector8.txt");
in21.open("detector9.txt");
in22.open("detector10.txt");
in23.open("detector11.txt");
in24.open("detector12.txt");
k=10000;

in1 >m1;
in2 >m2;
in3 >m3;
in4 >m4;
in5 >m5;
in6 >m6;
in7 >m7;
in8 >m8;
in9 >m9;
in10 >m10;
in11 >m11;
in12 >m12;

for (j=0; j<=18500;j++)
{
in13>>x[j] >>y[j] >>z[j] >>c1;
in14>>c2;
in15>>c3;
in16>>c4;
in17>>c5;
in18>>c6;
in19>>c7;
in20>>c8;
in21>>c9;
in22>>c10;
in23>>c11;
in24>>c12;
f=pow((c1-m1),2)/c1 + pow((c2-m2),2)/c2 + pow((c3-m3),2)/c3 +
pow((c4-m4),2)/c4 + pow((c5-m5),2)/c5 + pow((c6-m6),2)/c6 +
pow((c7-m7),2)/c7 + pow((c8-m8),2)/c8 + pow((c9-m9),2)/c9 +
pow((c10-m10),2)/c10 + pow((c11-m11),2)/c11 + pow((c12-m12),2)/c12;

if (f<k)
{
k=f;
a=x[j];
b=y[j];
c=z[j];
}
}
j=0;
cout <<a<<b<<c<<" "<<k<<endl;
out_file<<"\n"<<a<<" "<<b<<" "<<c<<endl;
in13.close();
in14.close();
in15.close();
in16.close();
in17.close();
in18.close();
in19.close();
in20.close();
in21.close();
in22.close();
in23.close();
in24.close();

}
//getch();
}

Nov 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,
I have a small program to read data from some data files , in it I use
string types to build the data file name but when I try to compile it I
get: (see code below error)
root@rob-laptop:/home/rob/pankaj# gcc ptcllocate.cpp
compile with g++, not gcc:
# g++ ptcllocate.cpp

.... and yes, I am sure you can get a more compact program by using
arrays and for() loops for instance.

Cheers,
Loic.

Nov 13 '06 #2

P: n/a

merrittr wrote:
I have a small program to read data from some data files , in it I use
string types to build the data file name but when I try to compile it I
get: (see code below error)
root@rob-laptop:/home/rob/pankaj# gcc ptcllocate.cpp
/tmp/ccg9j6Mi.o: In function `main':ptcllocate.cpp:(.text+0x99):
undefined reference to `std::allocator<char>::allocator()'
:ptcllocate.cpp:(.text+0xb9): undefined reference to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
::basic_string(char const*, std::allocator<charconst&)'
:ptcllocate.cpp:(.text+0xc7): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0xd5): undefined reference to
`std::allocator<char>::allocator()'
:ptcllocate.cpp:(.text+0xf5): undefined reference to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
::basic_string(char const*, std::allocator<charconst&)'
:ptcllocate.cpp:(.text+0x111): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x133): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x141): undefined reference to
`std::allocator<char>::allocator()'
:ptcllocate.cpp:(.text+0x161): undefined reference to
`std::basic_string<char, std::char_traits<char>, std::allocator<char>
::basic_string(char const*, std::allocator<charconst&)'
:ptcllocate.cpp:(.text+0x17d): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x196): undefined reference to
`std::allocator<char>::~allocator()'
:ptcllocate.cpp:(.text+0x1d6): undefined reference to
`std::allocator<char>::~allocator()'


any Idea what I am missing?
code:
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>

int main(int argc,char *argv[])
{
using namespace std;
int i,j;
long double
x[19500],y[19500],z[19500],c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,m1,m2,m3,m 4,m5,m6,m7,m8,m9,m10,m11,m12,a=0,b=0,c=0,f=0,k;
long double l, m, n, o ;

string beginning = "count";
string endding = ".txt";
string outf = "data";
string cf1(beginning + argv[0] + endding);
string cf2(beginning + argv[1] + endding);
string cf3(beginning + argv[2] + endding);
string cf4(beginning + argv[3] + endding);
string cf5(beginning + argv[4] + endding);
string cf6(beginning + argv[5] + endding);
string cf7(beginning + argv[6] + endding);
string cf8(beginning + argv[7] + endding);
string cf9(beginning + argv[8] + endding);
string cf10(beginning + argv[9] + endding);
string cf11(beginning + argv[10] + endding);
string cf12(beginning + argv[11] + endding);
string of1(outf + argv[1] + "_" + argv[11] + endding);
ifstream in1(cf1.c_str());
ifstream in2(cf2.c_str());
ifstream in3(cf3.c_str());
ifstream in4(cf4.c_str());
ifstream in5(cf5.c_str());
ifstream in6(cf6.c_str());
ifstream in7(cf7.c_str());
ifstream in8(cf8.c_str());
ifstream in9(cf9.c_str());
ifstream in10(cf10.c_str());
ifstream in11(cf11.c_str());
ifstream in12(cf12.c_str());
ifstream in13;
ifstream in14;
ifstream in15;
ifstream in16;
ifstream in17;
ifstream in18;
ifstream in19;
ifstream in20;
ifstream in21;
ifstream in22;
ifstream in23;
ifstream in24;

ofstream out_file;
out_file.open(of1.c_str());
while (!in1.eof())
{
in13.open("detector1.txt");
in14.open("detector2.txt");
in15.open("detector3.txt");
in16.open("detector4.txt");
in17.open("detector5.txt");
in18.open("detector6.txt");
in19.open("detector7.txt");
in20.open("detector8.txt");
in21.open("detector9.txt");
in22.open("detector10.txt");
in23.open("detector11.txt");
in24.open("detector12.txt");
k=10000;

in1 >m1;
in2 >m2;
in3 >m3;
in4 >m4;
in5 >m5;
in6 >m6;
in7 >m7;
in8 >m8;
in9 >m9;
in10 >m10;
in11 >m11;
in12 >m12;

for (j=0; j<=18500;j++)
{
in13>>x[j] >>y[j] >>z[j] >>c1;
in14>>c2;
in15>>c3;
in16>>c4;
in17>>c5;
in18>>c6;
in19>>c7;
in20>>c8;
in21>>c9;
in22>>c10;
in23>>c11;
in24>>c12;
f=pow((c1-m1),2)/c1 + pow((c2-m2),2)/c2 + pow((c3-m3),2)/c3 +
pow((c4-m4),2)/c4 + pow((c5-m5),2)/c5 + pow((c6-m6),2)/c6 +
pow((c7-m7),2)/c7 + pow((c8-m8),2)/c8 + pow((c9-m9),2)/c9 +
pow((c10-m10),2)/c10 + pow((c11-m11),2)/c11 + pow((c12-m12),2)/c12;

if (f<k)
{
k=f;
a=x[j];
b=y[j];
c=z[j];
}
}
j=0;
cout <<a<<b<<c<<" "<<k<<endl;
out_file<<"\n"<<a<<" "<<b<<" "<<c<<endl;
in13.close();
in14.close();
in15.close();
in16.close();
in17.close();
in18.close();
in19.close();
in20.close();
in21.close();
in22.close();
in23.close();
in24.close();

}
//getch();
}
With std::vector and a simple function to parse arguements, another to
read file input, your 131 lines would probably be reduced to a couple
dozen lines. Why not try reading one parameter, open one file using one
std::ifstream, do some error checking and then output to one file. One
leggo brick at a time. Code like you had 1 million of the above to
make. Once you prove one works, you can make a gazillion of them.

note:
std::vector< std::string vs(100000); // makes 100.000 strings
instantly

yes, man, one line of code made 100,000 strings.

beats doing:
std::string s0;
std::string s1;
and so on...

Nov 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.