g++ returns "undefined reference to"


I have a question about some problem that I have with g++.

I have a very simple application that is edited by Eclipse with c++ language in ubuntu operating system.

I want to use the classes of CLucene libraries.

But In spite of including header files and namesapces I get this error "undefined reference to `lucene::analysis::standard::StandardAnalyzer::StandardAnalyzer()"

Here is my simple application code:

#include <stdio.h>
#include </usr/include/CLucene/config/define_std.h>
#include </usr/include/CLucene/config/repl_wchar.h>
#define TCHAR wchar_t //it is necessary to be here

#include <CLucene.h>
#include <CLucene/util/Reader.h>
#include <iostream>
#include <CLucene/analysis/standard/StandardAnalyzer.h>

namespace lucene {
namespace analysis {
namespace standard{
class StandardAnalyzer;

using lucene::analysis::standard::StandardAnalyzer;

int main()
lucene::analysis::standard::StandardAnalyzer *a=new StandardAnalyzer();

return 0;


and according to eclipse this is the command that g++ runs to compile my code:


I really don't have any idea about the problem that it may have. I tried different format of creating instance of classes but i get the same error in all cases.

Please help me if you have any idea about it.

Best Regards
You are probably not linking to those libraries libs (.so or .a) look at the documentation and see what libs you need to link your program with.
Last edited on
The compiler is basically complaining about the fact that you haven't told it about


which is the constructor for the StandardAnalyser class.

You are forward declaring the class but not defining it which doesn't really make sense. If it is defined in the header files then you don't need to forward declare it. If it is a class the you are creating then just forward declaring it is not enough. You need to define the class. You seem to have straddled the fence.

In case you don't know
namespace lucene {
    namespace analysis {
        namespace standard{
            class StandardAnalyzer;

is the forward declaration. It just tells the compiler that the class exists, it doesn't tell the compiler anything about it. The compiler needs a class definition.

So, is it a class that is defined in the CLucene libraries or is it a class you are creating yourself? Your solution depends on your answer.

Thank you all so much for you answers.

Yes you are right.

StandardAnalyzer is a class That is defined in Clucene libraries.

I will apply what you guys recommended to me and tell you the result.

hi again

I wanted to link the libclucene.so to the project as you recommended but
Unfortunately, When i add this library in list of libraries and add the path of it (/usr/lib) in eclipse it returns :

g++ -L/usr/lib -o"CLuceneTemplate" ./main.o -llibclucene.so
/usr/bin/ld: cannot find -llibclucene.so

while when i see the path i can see the file in this path.

I searched about this error but i couldn't find any thing useful.

As it seems it happens with every library in any path because i checked different cases also.

would you please help me if you have any idea about it.

Best Regards,
you should miss out the 'lib' part of the library name and the extension, the command line should read:

g++ -L/usr/lib -o"CLuceneTemplate" ./main.o -lclucene
Last edited on

Thank you so much!!

it worked!!!

guys you helped me so much!

Topic archived. No new replies allowed.