我在课程中遇到一些问题。我认为这是链接器的一个问题。该程序没有给我任何语法问题和编译。这些问题来自该计划的一个班级。我试过从头开始重写这个,希望它是一个简单的语法错误,但是没有用。我还确保类文件位于包含目录列表中的目录中。
调用导致问题的FillerImage类的文件。
#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;
}
头文件
#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;
}
FillerImage继承的图像类是由我的老师创建的,并且在最后一个程序中运行良好,所以我认为这不是问题。
Netbeans给出的错误是
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架构x86_64的未定义符号:“FillerImage :: FillerImage(std :: basic_string,std :: allocator&gt;)”,引自: cs215pgm5.o中的loadFillerImagesFromFolder(std :: basic_string,std :: allocator&gt;)ld: 找不到架构的符号x86_64 collect2:ld返回1 退出状态make: * [cs215pgm5.app/Contents/MacOS/cs215pgm5]错误1
BUILD FAILED(退出值2,总时间:131ms)
感谢您提供的任何帮助。
答案 0 :(得分:1)
您的构建中似乎没有包含fillerimage.cpp
。它可能未在Qt应用程序的.pro文件中列为source
,如果您确实使用的是Qt。