1

这么小的程序让我抓狂。我总是收到以下错误消息:

Error   1   error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ErstesPraktikum::createNameString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?createNameString@ErstesPraktikum@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V23@00H@Z) referenced in function _main    Praktikum_gra.obj   GRA
Error   2   fatal error LNK1120: 1 unresolved externals C:\Users\xxx\Documents\Visual Studio 2008\Projects\GRA\Debug\GRA.exe    GRA

这是我的程序,其中包含ErstesPraktikumPraktikum_gra类以及相应的头文件。

我只想使用Praktikum_gra 类来调用ErstesPraktikum类的方法。我花了几个小时解决这个错误,但没有成功。这是编程错误还是配置问题?我最后的希望是你们中的某个人可以给我一个提示......

注意:String只是openCV的std::string的包装器。

ErstesPraktikum.h

#include <opencv2\core\core.hpp>

using namespace std;
using namespace cv;

class ErstesPraktikum
{
    private:
        String convertInteger(int);

    public:
        String createNameString(String, String, String, int);
        void readImage(String, Mat *);
        void extractObjects(int, Mat *, Mat *);
};

ErstesPraktikum.cpp

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <fstream>

using namespace std;
using namespace cv;


String convertInteger(int value) 
{
    stringstream ss;
    ss << value;
    return ss.str();
}

String createNameString(String path, String fileName, String fileExtension, int buildNumber)
{
    String pathString = path.append(fileName);
    pathString = pathString.append(".");
    pathString = pathString.append(convertInteger(buildNumber));
    pathString = pathString.append(".");
    pathString = pathString.append(fileExtension);

    return pathString;
}

void readImage(String nameString, Mat * image) 
{
   double mn = 0, mx = 0;
   image = &cv::Mat(cv::Size(512, 512), IPL_DEPTH_8U, 1);
   unsigned short *data;
   data = (unsigned short *)image->data;
   FILE *file;
   file = fopen(nameString.c_str(), "rb");

   fseek(file, 1340, SEEK_SET);
   fread(data, sizeof(unsigned short)*512*512, 1, file);
   fclose(file);


   //cv::cvSmooth(Image,Image);

   //cv::minMaxLoc(image, &mn, &mx, NULL, NULL, 0);
   //cv::convertScaleAbs(image, *target, 255/mx, -mn*255/mx);
}

void extractObjects(int threshold, Mat * img, Mat * binImg) 
{

}

Praktikum_gra.h

class Praktikum_gra
{
    public:
        int main(void);
}

Praktikum_gra.cpp

#include "ErstesPraktikum.h"

using namespace std;
using namespace cv;

    int main(void)
    { 
        String path("C:\\Users\\xxx\\xxx\\xxx\\GRA P1\\Head_M\\");
        String fileName("vhm");
        String fileExtension("dcm");
        ErstesPraktikum prak;

        for(int i = 1001; i <= 1245; i++) 
        {
            String nameString = prak.createNameString(path, fileName, fileExtension, i); // this line is the cause of the error message, but why ?
        }

        return 0;
    }

我已经尝试为所有方法添加类前缀,例如:

String ErstesPraktikum::createNameString(String path, String fileName, String fileExtension, int buildNumber)
{
    // [...]
}

但这会引发另一条错误消息:

Error   1   error C2653: 'ErstesPraktikum' : is not a class or namespace name   c:\users\xxx\documents\visual studio 2008\projects\gra\gra_u1\erstespraktikum.cpp   17  GRA
4

1 回答 1

2

你必须

#include "ErstesPraktikum.h"

ErstesPrakticum.cpp. 然后,您需要ErstesPrakticum::在实现中使用。

String ErstesPraktikum::createNameString( .... ) { .... }

等等。

于 2012-11-11T15:42:30.253 回答