CLucene 包装器的链接问题

发布于 2024-10-17 01:21:33 字数 2315 浏览 1 评论 0原文

我正在做一个来自 CLucene 的小包装。

ofxCLucene.h

#ifndef _OFXCLUCENE_
#define _OFXCLUCENE_

#include "ofMain.h"
#include "ofxXmlSettings.h"
#include "ofxDirList.h"
#include "CLucene.h"

using namespace lucene;
using namespace lucene::analysis;
using namespace lucene::analysis::standard;
using namespace lucene::index;
using namespace lucene::document;
using namespace lucene::queryParser;
using namespace lucene::search;
using namespace lucene::store;


class ofxCLucene {
private:
  string name;
  SimpleAnalyzer *sanalyzer; 
  Directory *dir;
  IndexWriter *writer;
  IndexReader *reader;

public:
  ofxCLucene(string name);
  ~ofxCLucene();

  void addDocumentsFromDirectory(string pathToDir);
  void addDocumentXML(ofxXmlSettings *docXML);

  void indexReader();
  void closeIndex();

  Hits* search(string query); 

};

#endif

ofxCLucene.cpp

#include "ofxCLucene.h"

//------------------------------------------------------------------------------
ofxCLucene::ofxCLucene(string name) {
  this->name = name;
  sanalyzer = new SimpleAnalyzer();
}

...

我编译它没有问题,但是当我将它放在我的项目中并创建一个新对象时,我收到了错误:

 "vtable for lucene::analysis::Analyzer", referenced from:


      __ZTVN6lucene8analysis8AnalyzerE$non_lazy_ptr in ofxCLucene.o


     (maybe you meant: __ZTVN6lucene8analysis8AnalyzerE$non_lazy_ptr)


  "vtable for lucene::analysis::SimpleAnalyzer", referenced from:


      __ZTVN6lucene8analysis14SimpleAnalyzerE$non_lazy_ptr in ofxCLucene.o


     (maybe you meant: __ZTVN6lucene8analysis14SimpleAnalyzerE$non_lazy_ptr)


ld: symbol(s) not found


collect2: ld returned 1 exit status

两者的源代码是:

class Analyzer:LUCENE_BASE{
public:

    virtual TokenStream* tokenStream(const TCHAR* fieldName, CL_NS(util)::Reader* reader)=0;

    virtual ~Analyzer(){
    }

    virtual int32_t getPositionIncrementGap(const TCHAR* fieldName);
};



class SimpleAnalyzer: public Analyzer {
public:
    TokenStream* tokenStream(const TCHAR* fieldName, CL_NS(util)::Reader* reader);
    ~SimpleAnalyzer(){}
};

我认为这是一个命名空间问题,我尝试调用

analyzer::SimpleAnalyzer *sanalyzer = new analyzer::SimpleAnalyzer();

,但问题仍然存在。

建议? 谢谢

I'm doing a small wrapper from CLucene.

ofxCLucene.h

#ifndef _OFXCLUCENE_
#define _OFXCLUCENE_

#include "ofMain.h"
#include "ofxXmlSettings.h"
#include "ofxDirList.h"
#include "CLucene.h"

using namespace lucene;
using namespace lucene::analysis;
using namespace lucene::analysis::standard;
using namespace lucene::index;
using namespace lucene::document;
using namespace lucene::queryParser;
using namespace lucene::search;
using namespace lucene::store;


class ofxCLucene {
private:
  string name;
  SimpleAnalyzer *sanalyzer; 
  Directory *dir;
  IndexWriter *writer;
  IndexReader *reader;

public:
  ofxCLucene(string name);
  ~ofxCLucene();

  void addDocumentsFromDirectory(string pathToDir);
  void addDocumentXML(ofxXmlSettings *docXML);

  void indexReader();
  void closeIndex();

  Hits* search(string query); 

};

#endif

ofxCLucene.cpp

#include "ofxCLucene.h"

//------------------------------------------------------------------------------
ofxCLucene::ofxCLucene(string name) {
  this->name = name;
  sanalyzer = new SimpleAnalyzer();
}

...

I have no problem compile it however when I put it on my project and create a new object I got the errors:

 "vtable for lucene::analysis::Analyzer", referenced from:


      __ZTVN6lucene8analysis8AnalyzerE$non_lazy_ptr in ofxCLucene.o


     (maybe you meant: __ZTVN6lucene8analysis8AnalyzerE$non_lazy_ptr)


  "vtable for lucene::analysis::SimpleAnalyzer", referenced from:


      __ZTVN6lucene8analysis14SimpleAnalyzerE$non_lazy_ptr in ofxCLucene.o


     (maybe you meant: __ZTVN6lucene8analysis14SimpleAnalyzerE$non_lazy_ptr)


ld: symbol(s) not found


collect2: ld returned 1 exit status

The source code from both is:

class Analyzer:LUCENE_BASE{
public:

    virtual TokenStream* tokenStream(const TCHAR* fieldName, CL_NS(util)::Reader* reader)=0;

    virtual ~Analyzer(){
    }

    virtual int32_t getPositionIncrementGap(const TCHAR* fieldName);
};



class SimpleAnalyzer: public Analyzer {
public:
    TokenStream* tokenStream(const TCHAR* fieldName, CL_NS(util)::Reader* reader);
    ~SimpleAnalyzer(){}
};

I thought it was a namespace issue and I try calling

analyzer::SimpleAnalyzer *sanalyzer = new analyzer::SimpleAnalyzer();

but the problem remain.

Suggestions?
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

︶ ̄淡然 2024-10-24 01:21:33

我猜这是在mac上?我对mac上的编译不是很熟悉。

你能告诉我们你是如何编译的(即什么编译标志等)。也许添加一个可编译的示例)。

另外,您可以使用您的环境编译此代码吗?

#include "CLucene.h"
int main(){
   lucene::analysis::SimpleAnalyzer *sanalyzer = new lucene::analysis::SimpleAnalyzer();
}

我使用以下命令编译了上面的代码,没有任何问题。 (-fPIC 因为我在 64 位机器上)。

g++ test.cpp -lclucene -I/usr/lib -fPIC

This is on mac, I'm guessing? I'm not very familiar with compiling on mac.

Can you tell us how you're compiling (i.e. what compile flags, etc). And perhaps add an example which is compilable).

Also, can you compile this code using your environment?

#include "CLucene.h"
int main(){
   lucene::analysis::SimpleAnalyzer *sanalyzer = new lucene::analysis::SimpleAnalyzer();
}

I compiled the above code with the following command with no problems. (-fPIC because i'm on an 64 bit machine).

g++ test.cpp -lclucene -I/usr/lib -fPIC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文