Dev-C++/gcc compile question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikejfe
    New Member
    • Feb 2007
    • 12

    Dev-C++/gcc compile question

    Hi all. I've written a program that dynamically allocates memory for a 3dim array, reads a file into that array, does some stuff to the data in the array and then outputs the array to a file.

    I can compile my program with Dev-C++ and run it all day long on my laptop (Windows XP). The problem with this is my laptop is slow. So, I tried to compile the code with gcc on my Linux box. gcc, however, doesn't seem to like my code.

    The error I get says: "In function `__static_initi alization_and_d estruction_0(in t, int':." Then errors go on for another page or two. I've included the code that makes the array (if I need to include more code, I'll be more than happy).

    I know about enough C++ to get done what I need, and am a new Linux user.

    Thanks in advance for your help.

    Code:
    #include<fstream>
    #include<iostream>
    #include<math.h>
    #include<string>
    
    using namespace std;
    
    // Voxel information array
    float ***xyz = NULL;
    
    int main()
    {
    // Ask user for input file
    string filename;
    cout << "File, array size (*.* DIM DIM DIM): ";
    int numOfVoxelsX;
    int numOfVoxelsY;
    int numOfVoxelsZ;
    cin >> filename >> numOfVoxelsX >> numOfVoxelsY >> numOfVoxelsZ;
    string outputFileName;
    cout << endl;
    cout << "Output File Name (*.*): ";
    cin >> outputFileName; 
    
    cout << "Initializing" << endl;
    
    xyz = new float**[numOfVoxelsX];
    for (i = 0; i<numOfVoxelsX; i++)
      {
        xyz[i] = new float*[numOfVoxelsY];
        for (j = 0; j<numOfVoxelsY; j++)
          {
            xyz[i][j] = new float[numOfVoxelsZ];
          }
      }
    cout << "Space allocated." << endl;
    
    .....
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You didn't post this function: __static_initia lization_and_de struction_0.

    And you didn't post the errors you are getting. Generally, only the first error is important. Fix it and the others may go away.

    Comment

    • mikejfe
      New Member
      • Feb 2007
      • 12

      #3
      Honestly, I don't even know what function that is. I didn't knowingly call it. This program is so simplistic; there is no header file and everything I do is completely contained in int main().

      The first few lines of the errors are:
      Code:
      /tmp/ccN8BUK4.o: In function `__static_initialization_and_destruction_(int, int)':
      VoxelizedPhantomResizer.cpp:(.test+0x23): undefiend reference to 'std::ios_base:Init:Init()'
      /tmp/ccN8BUK4.o: In function `__static_initialization_and_destruction_(int, int)':
      VoxelizedPhantomResizer.cpp:(.test+0x23): undefiend reference to 'std::ios_base:Init:~Init()'
      The rest of my code follows (continuing from my first post):
      Code:
      ......
      
      // Some vars for counting things in loops
      int i = 0;
      int j = 0;
      int k = 0;
      
      // Used to convert the var read from file into a double
      const char *filevalueConstChar;
      float filevalueFloat;
      string filevalue;
      
      // Write to the 3Dim array
      i = 0; j = 0; k = 0;
      ifstream fin(filename.c_str(), ios::in);
        if (fin.is_open())
          {
            cout << endl;
            cout << "Loading " << filename.c_str() << endl;
            while(!fin.eof())
              {          
                ws(getline(fin,filevalue, ' '));
                filevalueConstChar = filevalue.c_str();
                filevalueFloat = (float) atof (filevalueConstChar);
                xyz[i][j][k] = filevalueFloat;
      
                i = (i+1)%numOfVoxelsX;
                if (i==0)
                    {j = (j+1)%numOfVoxelsY;}
                if (i==0 && j==0)
                  {
                    if ((int)k%(numOfVoxelsZ/10)==0)
                      {
                        cout << (float) k*100.0/numOfVoxelsZ << "%" << endl;
                      }
                    k = (k+1)%numOfVoxelsZ;
                  }
              }
            fin.close();
          }
        else
          {
            cout << endl;
            cout << "--ERROR--" << endl;
            cout << "Unable to open file: " << filename.c_str() << endl << endl << endl;          
          }
      cout << filename.c_str() << " loaded." << endl;
      
      // Find the phantom edges and clip
      i=0;
      j=0;
      k=0;
      // Vars used for setting places to clip superfluious voxels
      int maxX = 0, minX = numOfVoxelsX;
      int maxY = 0, minY = numOfVoxelsY;
      int maxZ = 0, minZ = numOfVoxelsZ;
      // Flags for finding edges
      bool foundMinX = false;
      bool foundMinY = false;
      bool foundMinZ = false;
      
      cout << "Finding phantom edges...";
      while(k!=numOfVoxelsZ)
        {
          if(xyz[i][j][k] != 0) 
            {
              if (i<minX)
                  {minX = i;}
              foundMinX = true;
                          
              if (j<minY)
                  {minY = j;}
              foundMinY = true;
                          
              if (k<minZ)
                  {minZ = k;}
              foundMinZ = true;
            }
              
          if(xyz[i][j][k] == 0 && foundMinX == true)
            {
              if (maxX<i)
                  {maxX = i;}
              foundMinX = false;
            }
              
          if(xyz[i][j][k] == 0 && foundMinY == true)
            {
              if (maxY<j)
                  {maxY = j;}
              foundMinY = false;
            }
              
          if(xyz[i][j][k] == 0 && foundMinZ == true)
            {
              if (maxZ<k)
                  {maxZ = k;}
              foundMinZ = false;
            }
                     
          i = (i+1)%numOfVoxelsX;
          if (i==0)
              {j = (j+1)%numOfVoxelsY;}
          if (i==0 && j==0)
              {k++;}
        }
      cout << "done." << endl;
      // This is the end of finding the phantom edges.
      
      cout << "Reorganizing...";
      
      int clippingVolumeUB;
      int clippingVolumeLB;
      
      if (maxX>maxY && maxX>maxZ)
        {
          clippingVolumeUB = maxX;
        }
      if (maxY>maxX && maxY>maxZ)
        {
          clippingVolumeUB = maxY;
        }
      if (maxZ>maxX && maxZ>maxX)
        {
          clippingVolumeUB = maxZ;
        }
      
      i=clippingVolumeUB;
      j=clippingVolumeUB;
      k=clippingVolumeUB;
      
      if (minX<minY && minX<minZ)
        {
          clippingVolumeLB = minX;
        }
      if (minY<minX && minY<minZ)
        {
          clippingVolumeLB = minY;
        }
      if (minZ<minX && minZ<minX)
        {
          clippingVolumeLB = minZ;
        }
      
      i=clippingVolumeLB;
      j=clippingVolumeLB;
      k=clippingVolumeLB;
      
      cout << "Writing " << outputFileName.c_str() << endl << endl;
      
      ofstream fOut(outputFileName.c_str(),ios::out);
      if (!fOut)
        {
          cout << "Unable to open file for writing" << endl;
        }
      else
        {
          for(k=0; k<numOfVoxelsZ; k++)
            {
              if((int)k%(numOfVoxelsZ/10)==0)
                {
                  cout << "Writing Slice: " << k+1;
                }
              for(j=0; j<numOfVoxelsY; j++)
                {
                  for(i=0; i<numOfVoxelsX; i++)
                    {
                      fOut << xyz[i][j][k] << " ";
                    }
                  fOut << endl;
                }
                if(k%(numOfVoxelsZ/10)==0)
                  {
                    cout << "    Percent Done: " << (k*100/numOfVoxelsZ) << endl;
                  }
                         
            }
         fOut.close();
         }
      
      return(0)

      Comment

      Working...