user1072543
user1072543

Reputation:

Suspected linking issue with self created inherited class

I am having some issues with a program for class. I believe it to be an issue with the linker. The program gives me no syntax issues and compiles. The issues arises from a class in the program. I have tried rewriting this from scratch hoping it to be a simple syntax error, but that did not work. I have also made sure that the class files were in a directory that was included in the list of included directories.

The file calling the FillerImage class that causes issues.

#include <cstdlib>
#include <sstream>
#include <iostream>


#include "globals.h"  //some global variables are included here
#include "pixel.h"  //includes the pixel class for storing individual pixels
#include "image.h"  //includes the image class we will be using.
#include "FillerImage.h"

using namespace std;

//declare your global variables here!
image* IM;

//load the filler images from the given folder into a vector of fillerImage.
bool loadFillerImagesFromFolder(string folder) 
{
    for (int i = FIRST_FILLER_NUMBER; i<= LAST_FILLER_NUMBER; i++){
        stringstream num;
        num << i;
        string filepath = folder + "/" + num.str() + FILLER_IMAGE_EXT;

        FillerImage* tmpFil = new FillerImage(filepath);
    }
    return false;
}

The header file

#ifndef FILLERIMAGE_H
#define FILLERIMAGE_H

#include "image.h"
#include "pixel.h"

using namespace std;

class FillerImage :image
{
    public:
        FillerImage(string filepath);
        bool setAverageColour();
    private:
        int timesUsed;
        pixel averageColour;
};


#endif

.

#include "FillerImage.h"
#include "pixel.h"
#include "image.h"

using namespace std;

FillerImage::FillerImage(string filepath):image(filepath){
    timesUsed = 0;
}

bool FillerImage::setAverageColour(){
    pixel** pix = getPixels();
    int height = getHeight();
    int width = getWidth();
    int averageRed, averageBlue, averageGreen = 0;
    for (int i = 0; i < height; i++){
        for (int j = 0; j< width; j++){
            averageRed += pix[i][j].red;
            averageBlue += pix[i][j].blue;
            averageGreen += pix[i][j].green;
        }
    }
    pixel tmppix;
    int pixels = width*height;
    tmppix.red = averageRed/pixels;
    tmppix.blue = averageBlue/pixels;
    tmppix.green = averageGreen/pixels;
    averageColour = tmppix;
}

The image class which FillerImage inherits from was created by my teacher and worked fine in the last program, so I assume this is not the issue.

The error given by Netbeans is

g++ -headerpad_max_install_names -o cs215pgm5.app/Contents/MacOS/cs215pgm5 mainForm.o image.o cs215pgm5.o main.o moc_mainForm.o -F/Library/Frameworks -L/Library/Frameworks -framework QtGui -framework QtCore Undefined symbols for architecture x86_64: "FillerImage::FillerImage(std::basic_string, std::allocator >)", referenced from: loadFillerImagesFromFolder(std::basic_string, std::allocator >)in cs215pgm5.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make: * [cs215pgm5.app/Contents/MacOS/cs215pgm5] Error 1

BUILD FAILED (exit value 2, total time: 131ms)

Thanks for any help you can provide.

Upvotes: 0

Views: 138

Answers (1)

arne
arne

Reputation: 4674

It seems you haven't included fillerimage.cpp in your build. It probably isn't listed as a source in the .pro file of your Qt Application, if indeed you are using Qt.

Upvotes: 1

Related Questions