Linking problem with wrapper for CLucene

503 views Asked by At

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

1

There are 1 answers

0
bvanklinken On

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