6 Replies - 4568 Views - Last Post: 28 February 2010 - 10:03 PM Rate Topic: -----

#1 ytuser  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-February 10

the errors of C compiling the geotiff program in linux

Posted 23 February 2010 - 09:52 AM

Hi,
This is a geotiff image copy program. Does someone can take a look for these errors.
1.I have stdafx.h in the current folder
2.tiffio.h in the /usr/include/
3.xtiffio.h and geotiff.h in the /usr/include/geotiff/
4.the PATH=/home/ytuser/local/linux/bin:/usr/include/geotiff:/usr/lib/gmt/bin:/usr/games:.:./bin:/home/ytuser/bin:/usr/local/bin:/usr/sbin:/usr/bin/X11:/usr/X11/bin:/bin:/usr/bin
Thanks

ytuser

The message of errors
**********************************************************************************************
copygtiff.cpp:18:21: error: xtiffio.h: No such file or directory
copygtiff.cpp:19:40: error: geotiff.h: No such file or directory
copygtiff.cpp: In function ‘int main(int, char**)’:
copygtiff.cpp:24: error: ‘GTIF’ was not declared in this scope
copygtiff.cpp:24: error: ‘gtiff’ was not declared in this scope
copygtiff.cpp:59: error: ‘XTIFFOpen’ was not declared in this scope
copygtiff.cpp:71: error: ‘GTIFNew’ was not declared in this scope
copygtiff.cpp:76: error: ‘XTIFFClose’ was not declared in this scope
copygtiff.cpp:140: error: ‘XTIFFClose’ was not declared in this scope
copygtiff.cpp:141: error: ‘GTIFFree’ was not declared in this scope
copygtiff.cpp:157: error: ‘XTIFFOpen’ was not declared in this scope
*******************************************************************************************[/color]


[color="#0000FF"]
The program of copying geotiff
*********************************************************************
#include "stdafx.h"
#include <cstdlib> 
#include <stdio.h> 
#include <math.h>  
#include <tiffio.h>
#include <xtiffio.h>
#include <geotiff.h> // For GeoTIFF I/O


int main(int argc, char *argv[]){
        TIFF *image;             
        GTIF *gtiff;             
        uint16 photo, bps, spp,rps,comp,pconfig;
        uint32 width,height;                    
        tsize_t stripSize;                      
        unsigned long imageOffset, result;      
        int stripMax, stripCount;               
        unsigned char *buffer;                  
        unsigned long bufferSize;               

        //      Memory for Input and output file names:

        char infile[1000],outfile[1000];


        //      Input the source file:

        printf("Source File: ", infile);
        scanf ("%s", infile);           

        //---------------------------------------------------------------------
        //                                                                     
        // Open the TIFF image:                                                
        //                                                                     
        //              ** Normal TIFF images should be opened with TIFFOpen   
        //                      but XTIFFOpen adds some different functiois for us
        //                      to recognize GeoTIFF Specification                
        //                                                                        
        //              ** Calling Open will automatically read the first         
        //                              IFD For Us                                
        //                                                                        
        //                      ---> For multiple pages/images ... subsequent calls
        //                               to TIFFReadDirectory are necessary.       
        //                                                                         
        //---------------------------------------------------------------------    

        if((image = XTIFFOpen(infile, "r")) == NULL)
        {                                           
            printf("The Given TIFF Image: %s could not be opened.\n", infile);
                exit(42);                                                     
        }                                                                     

        //---------------------------------------------------------------------
        //                                                                     
        //      Using our TIFF image we create a geo TIFF                      
        //                                                                     
        //----------------------------------------------------------------------

        gtiff = GTIFNew(image);

        if (!gtiff)
    {              
        printf("The Given GeoTIFF Image: %s could not be opened.\n",infile);
                XTIFFClose(image);                                          
                exit(42);                                                   
    }                                                                       

        //---------------------------------------------------------------------
        //      Grab information fields from the image that we will need       
        //      for writing purposes                                           
        //----------------------------------------------------------------------

        TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps);
        TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);
        TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width);   
        TIFFGetField(image, TIFFTAG_IMAGELENGTH, &height); 
        TIFFGetField(image, TIFFTAG_ROWSPERSTRIP, &rps);   
        TIFFGetField(image, TIFFTAG_COMPRESSION,&comp);    
        TIFFGetField(image, TIFFTAG_PHOTOMETRIC,&photo);   
        TIFFGetField(image, TIFFTAG_PLANARCONFIG, &pconfig);

        //------------------------------------------------------------------------------------
        //                                                                                    
        //              Reading in the Image Data                                             
        //                                                                                    
        //------------------------------------------------------------------------------------

        //      Strip Size Calculation

        stripSize =  TIFFStripSize (image);

        //      Determination of the Number of Strips

        stripMax   = TIFFNumberOfStrips (image);
        imageOffset = 0;                        

        bufferSize = TIFFNumberOfStrips (image) * stripSize;

        buffer = new unsigned char[bufferSize];

        if (!(buffer)){
                fprintf(stderr, "Could not allocate enough memory for the uncompressed image\n");
                exit(42);                                                                        
        }                                                                                        

        //      This is a Strip Oriented IO Approach.

        for (stripCount = 0; stripCount < stripMax; stripCount++){
                if((result = TIFFReadEncodedStrip (image, stripCount,
                                              buffer + imageOffset,  
                                              stripSize)) == -1){    

                        fprintf(stderr, "Read error on input strip number %d\n", stripCount);
                        exit(42);                                                            

            }
            imageOffset += result;
        }                         

        //-------------------------------------------------------------------------------------
        //                                                                                     
        //              End of Reading                                                         
        //                                                                                     
        //---------------------------------------------------------------------------------------

        // clean up the image because we have all the information we need:

        XTIFFClose(image);
        GTIFFree(gtiff);  



        //      Input the destination file:
        //---------------------------------------------------------------------------------------
        //
        //              Write data to new file
        //
        //----------------------------------------------------------------------------------------

        printf("Destination File: ", outfile);
        scanf ("%s", outfile);

        // Open the TIFF file for writing

        if((image = XTIFFOpen(outfile, "w")) == NULL){
                printf("Could not open output.tif for writing\n");
                exit(42);
        }

         // We need to set some values for basic tags before we can add any data

        TIFFSetField(image, TIFFTAG_IMAGEWIDTH, width);
        TIFFSetField(image, TIFFTAG_IMAGELENGTH, height);
        TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, bps);
        TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, spp);
        TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, height);
        TIFFSetField(image, TIFFTAG_COMPRESSION, comp);
        TIFFSetField(image, TIFFTAG_PHOTOMETRIC, photo);
        TIFFSetField(image, TIFFTAG_PLANARCONFIG, pconfig);

        // Write the information to the file

        TIFFWriteEncodedStrip(image, 0, buffer, bufferSize);

        // Close the file

        XTIFFClose(image);

        //---------------------------------------------------------------------------------------
        //
        //              End of Writing Data to New File.
        //
        //---------------------------------------------------------------------------------------


        //      clean up the buffers

        free(buffer);

        printf("Copy Successful.\n");

        return(1);
}


This post has been edited by JackOfAllTrades: 23 February 2010 - 10:23 AM
Reason for edit:: Added code tags. PLEASE! [code]...PUT YOUR CODE IN HERE!!!...[/code]


Is This A Good Question/Topic? 0
  • +

Replies To: the errors of C compiling the geotiff program in linux

#2 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: the errors of C compiling the geotiff program in linux

Posted 23 February 2010 - 10:18 AM

You must add the path to the header files to the compiler's search path. If you are using gcc, you can do this as follows:
gcc -I /usr/include/geotiff ...

Was This Post Helpful? 0
  • +
  • -

#3 ytuser  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-February 10

Re: the errors of C compiling the geotiff program in linux

Posted 24 February 2010 - 08:24 AM

Hi Paul it makes more errors


heron1 ytuser 314 % gcc -I /usr/include/geotiff copygtiff.cpp
/tmp/ccEbeXx7.o: In function `main':
copygtiff.cpp:(.text+0x66): undefined reference to `XTIFFOpen'
copygtiff.cpp:(.text+0xaa): undefined reference to `GTIFNew'
copygtiff.cpp:(.text+0xdd): undefined reference to `XTIFFClose'
copygtiff.cpp:(.text+0x109): undefined reference to `TIFFGetField'
copygtiff.cpp:(.text+0x129): undefined reference to `TIFFGetField'
copygtiff.cpp:(.text+0x149): undefined reference to `TIFFGetField'
copygtiff.cpp:(.text+0x169): undefined reference to `TIFFGetField'
copygtiff.cpp:(.text+0x189): undefined reference to `TIFFGetField'
/tmp/ccEbeXx7.o:copygtiff.cpp:(.text+0x1a9): more undefined references to `TIFFGetField' follow
/tmp/ccEbeXx7.o: In function `main':
copygtiff.cpp:(.text+0x1f7): undefined reference to `TIFFStripSize'
copygtiff.cpp:(.text+0x20b): undefined reference to `TIFFNumberOfStrips'
copygtiff.cpp:(.text+0x229): undefined reference to `TIFFNumberOfStrips'
copygtiff.cpp:(.text+0x248): undefined reference to `operator new[](unsigned int)'
copygtiff.cpp:(.text+0x2cc): undefined reference to `TIFFReadEncodedStrip'
copygtiff.cpp:(.text+0x33f): undefined reference to `XTIFFClose'
copygtiff.cpp:(.text+0x34d): undefined reference to `GTIFFree'
copygtiff.cpp:(.text+0x38f): undefined reference to `XTIFFOpen'
copygtiff.cpp:(.text+0x3db): undefined reference to `TIFFSetField'
copygtiff.cpp:(.text+0x3fb): undefined reference to `TIFFSetField'
copygtiff.cpp:(.text+0x41f): undefined reference to `TIFFSetField'
copygtiff.cpp:(.text+0x443): undefined reference to `TIFFSetField'
copygtiff.cpp:(.text+0x463): undefined reference to `TIFFSetField'
/tmp/ccEbeXx7.o:copygtiff.cpp:(.text+0x487): more undefined references to `TIFFSetField' follow
/tmp/ccEbeXx7.o: In function `main':
copygtiff.cpp:(.text+0x4f9): undefined reference to `TIFFWriteEncodedStrip'
copygtiff.cpp:(.text+0x507): undefined reference to `XTIFFClose'
/tmp/ccEbeXx7.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6037
  • View blog
  • Posts: 23,435
  • Joined: 23-August 08

Re: the errors of C compiling the geotiff program in linux

Posted 24 February 2010 - 08:28 AM

You are trying to compile C++ with the C compiler.

You must also link to the TIFF library.
Was This Post Helpful? 0
  • +
  • -

#5 ytuser  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-February 10

Re: the errors of C compiling the geotiff program in linux

Posted 25 February 2010 - 07:56 AM

View PostJackOfAllTrades, on 24 February 2010 - 07:28 AM, said:

You are trying to compile C++ with the C compiler.

You must also link to the TIFF library.




Hi,
I also set the tiff library PATH, but it still not work.

The PATH
/home/ytuser/local/linux/bin:/usr/include:/usr/include/geotiff:/usr/lib/gmt/bin:/usr/games:.:./bin:/home/ytuser/bin:/usr/local/bin:/usr/sbin:/usr/bin/X11:/usr/X11/bin:/bin:/usr/bin:

The errors
copygtiff.cpp:18:21: error: xtiffio.h: No such file or directory
copygtiff.cpp:19:40: error: geotiff.h: No such file or directory
copygtiff.cpp: In function ‘int main(int, char**)’:
copygtiff.cpp:24: error: ‘GTIF’ was not declared in this scope
copygtiff.cpp:24: error: ‘gtiff’ was not declared in this scope
copygtiff.cpp:59: error: ‘XTIFFOpen’ was not declared in this scope
copygtiff.cpp:71: error: ‘GTIFNew’ was not declared in this scope
copygtiff.cpp:76: error: ‘XTIFFClose’ was not declared in this scope
copygtiff.cpp:140: error: ‘XTIFFClose’ was not declared in this scope
copygtiff.cpp:141: error: ‘GTIFFree’ was not declared in this scope
copygtiff.cpp:157: error: ‘XTIFFOpen’ was not declared in this scope
Was This Post Helpful? 0
  • +
  • -

#6 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: the errors of C compiling the geotiff program in linux

Posted 25 February 2010 - 10:51 PM

If you have geotiff.h in the same directory as your .c file then you should be able to list it like:

#include "geotiff.h"


Not like...
#include <geotiff.h>

as you did above.

If it is not in that directory you can either copy and paste it there or list the path. Like...
#include "/usr/var/geotiff.h"


Or whatever the case may be. Then gcc should be able to find it.
Was This Post Helpful? 0
  • +
  • -

#7 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: the errors of C compiling the geotiff program in linux

Posted 28 February 2010 - 10:03 PM

View PostJackOfAllTrades, on 24 February 2010 - 07:28 AM, said:

You are trying to compile C++ with the C compiler.

Yes, my mistake. I did not realize it was C++. The command should be g++, not gcc.

To include the library during linking, you can specify the path on the command line. If for example the library is in directory /usr/local/lib, you would say:
g++ -I /usr/include/geotiff -l /usr/local/lib ...

This post has been edited by Paul-: 28 February 2010 - 10:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1