0

I have a problem running a test file I got from my teacher. I got 3 errors like

C:\Users\Ragnar\Documents\c++\MRO\tga_test.o    tga_test.cpp:(.text+0xe3): undefined reference to `readPGMB_header(char const*, int*, int*, int*)'

and later collect2.exe [Error] ld returned 1 exit status

I tried this on another computer and it works without problems. I have Windows 8 and Dev C++ 5.7.1. I should install smth or what. Below is my cpp code + header code.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>

#include "Ttiming.h"
#include "TPGM.h"

TTiming tt;//klasa do mierzenia czasu wykonywania się poszczególnych funkcji

bool replace(std::string& str, const std::string& from, const std::string& to) {
    size_t start_pos = str.find(from);
    if(start_pos == std::string::npos)
        return false;
    str.replace(start_pos, from.length(), to);
    return true;
}

int main(int argc, char **argv)
{
    int rows, cols;           
    int max_color;
    int hpos, i,j;      

    std::string infname = "maly.pgm";

    if ( (hpos = readPGMB_header(infname.c_str(), &rows, &cols, &max_color)) <= 0 )    exit(1);

    unsigned char **a = new unsigned char* [rows];
    a[0] = new unsigned char [rows*cols];
    for(int i = 1; i < rows; i++)
        a[i] = a[i-1] + cols;

    if( readPGMB_data(a[0], infname.c_str(), hpos, rows, cols, max_color) == 0 )       exit(1);

    //przygotowanie czarno-bialej tablicy wyjsciowej

    unsigned char **b = new unsigned char* [rows];
    b[0] = new unsigned char [rows*cols];
    for(int i = 1; i < rows; i++)
        b[i] = b[i-1] + cols;

    tt.Begin();     //start to measure the time

    for (i=0; i< rows; ++i){
        for (j=0; j< cols; ++j){

            b[i][j] = (a[i][j] > 128 ) ?  255 : 0;

        }
    }

    double elapsed = tt.End();  //stop and read elapsed time in ms (miliseconds)

    std::string outfname = infname;
    replace(outfname, ".pgm", "_simple.pgm");

    if( writePGMB_image(outfname.c_str(), b[0], rows, cols, 255) == 0)     exit(1);

    free( a );
    free( b );

   printf("czas binaryzacji : %f ms", elapsed);
   getchar ();

   return 0;
}

And Header file:

/*
 * Created: 2011-11-04
 * Author : Tomasz Gąciarz
 * 
 * Copyright (C) 2011.  All rights reserved.
 */

#if !defined(DEF_TPGM)
#define DEF_TPGM

int readPGMB_header(const char *fname, int *rows, int *cols, int *max_color);
int readPGMB_data(unsigned char *image,const  char *fname, int hlen, int rows, int cols, int max_color);
int writePGMB_image(const char *fname, unsigned char *image, int rows,  int cols, int max_color);

int readPPMB_header(const char *fname, int *rows, int *cols, int *max_color);
int readPPMB_data(unsigned char *imageR, unsigned char *imageG, unsigned char *imageB,const  char *fname, int hlen, int rows, int cols, int max_color);
int writePPMB_image(const char *fname, unsigned char *imageR, unsigned char *imageG, unsigned char *imageB, int rows,  int cols, int max_color);

#endif
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
Rag
  • 65
  • 9

0 Answers0