1

Whenever I try to compile a C++ file with IOStream , I get this error.. I've tried reinstalling GCC G++ (both 4.6 and 4.9) AND cpp.. It hasnt helped (or maybe I didnt do it the right way). How do I fix this error

In file included from /usr/include/c++/4.9/bits/localefwd.h:40:0,
             from /usr/include/c++/4.9/ios:41,
             from /usr/include/c++/4.9/ostream:38,
             from /usr/include/c++/4.9/iostream:39,
             from Integration_Any.cpp:1:
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:52:23: error:‘uselocale’was         not declared in this scope
   extern "C" __typeof(uselocale) __uselocale;
                   ^
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:52:45: error: invalid type in    declaration before ‘;’ token
   extern "C" __typeof(uselocale) __uselocale;
                                         ^
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h: In function ‘int     std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’:       /usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:75:53: error:     ‘__gnu_cxx::__uselocale’ cannot be used as a function
     __c_locale __old = __gnu_cxx::__uselocale(__cloc);
                                                 ^
/usr/include/x86_64-linux-gnu/c++/4.9/bits/c++locale.h:100:33: error:     ‘__gnu_cxx::__uselocale’ cannot be used as a function
     __gnu_cxx::__uselocale(__old);
                             ^

The code is MPI

#include <iostream>
#include <math.h>
#include <stdlib.h>
#include "/home/pnpninja/PC/Monte Carlo/prng_engine.hpp"
#include "mpi.h"
#define sitmo_rand_max 4294967295
using namespace std;

int main(int argc,char* argv[])
{
//Initialization of variables
  int numprocs,myid,rc;
  double     iterations,eachintegration,integrationsum,pi,start,total_time,actualsum,llimit,rlimit,eac    hllimit,eachrlimit,coefficients[26],highest_coefficient;
    //Initialization on MPI Variables
  MPI_Init(&argc,&argv);
  MPI_Status status;
  MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD,&myid);
  //Get number of iterations in MASTER Process / Process 0
  if(myid == 0)
  {
      cout<<"Enter the highest coeffecient (highest is 25): ";
      cin>>highest_coefficient;
      for(int temp=highest_coefficient;temp>=0;temp--)
      {
        printf("Enter the coefficient of degree %d : ",temp);
        cin>>coefficients[temp];
      }
      cout<<"Enter the lower limit : ";
      cin>>llimit;
      cout<<"Enter the upper limit : ";
      cin>>rlimit;
      cout<<"Enter the number of iterations : ";
      cin>>iterations;
      start = MPI_Wtime();
  }
  //Broadcast it to all other processes
  MPI_Bcast(&highest_coefficient,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
    MPI_Bcast(coefficients,26,MPI_DOUBLE,0,MPI_COMM_WORLD);
  MPI_Bcast(&llimit,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
  MPI_Bcast(&rlimit,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
  MPI_Bcast(&iterations,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
  //Parallel Random Generator with seed as Process ID
  sitmo::prng_engine eng(MPI_Wtime());
  eachintegration=0;
  eachllimit = llimit+(((rlimit-llimit)/numprocs)*myid);
  eachrlimit = llimit+(((rlimit-llimit)/numprocs)*(myid+1));
  for(int a=1;a<=iterations/numprocs;a++)
  {
    double point = eachllimit + ((double(eng())/(double(sitmo_rand_max)))*(eachrlimit-    eachllimit));
    for(int b=0;b<=highest_coefficient;b++)
    {
      eachintegration+=(coefficients[b]*(pow(point,b)));
    }
  }
  rc = MPI_Reduce(&eachintegration,&integrationsum,1, MPI_DOUBLE, MPI_SUM,0,     MPI_COMM_WORLD);
  if(myid == 0)
  {

    total_time = MPI_Wtime() - start;
    cout<<"\nThe integration by Monte Carlo method is :    "<<((integrationsum/iterations)*    (pow(rlimit-llimit,1)));
    actualsum=0;
    for(int c=0;c<=highest_coefficient;c++)
    {
      actualsum+=(coefficients[c]*((pow(rlimit,c+1))-(pow(llimit,c+1)))/(double(c+1)));
    }
    cout<<"\nThe error is : "<<((integrationsum/iterations)*(pow(rlimit-llimit,1)))-    actualsum;
cout<<"\nThe time taken is : "<<total_time<<"\n";
  }
      MPI_Finalize();
}

command to compile

mpic++ Int_Any Integration_Any.cpp -lm

Even a simple Hello World program wont compile as it gives me this error

6
  • 1
    Can you post: 1. The code you tried to compile (or a short version of it), 2. The exact command you used to compile, and 3. The complete error message?
    – muru
    Nov 13, 2014 at 4:31
  • thats the complete error message im seeing on the screen Nov 13, 2014 at 4:39
  • 1
    Do you have the build-essential package installed?
    – ubfan1
    Nov 13, 2014 at 5:02
  • yes. I have it. Nov 13, 2014 at 8:58
  • Even after purging and reinstalling, im getting this error.. I think my header files in /usr/include are corrupted... from where do i get them ? Nov 13, 2014 at 10:44

0

You must log in to answer this question.

Browse other questions tagged .