CLucene 包装器的链接问题
我正在做一个来自 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜这是在mac上?我对mac上的编译不是很熟悉。
你能告诉我们你是如何编译的(即什么编译标志等)。也许添加一个可编译的示例)。
另外,您可以使用您的环境编译此代码吗?
我使用以下命令编译了上面的代码,没有任何问题。 (-fPIC 因为我在 64 位机器上)。
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?
I compiled the above code with the following command with no problems. (-fPIC because i'm on an 64 bit machine).