Find the answer to your Linux question:
Results 1 to 7 of 7
Hi 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    6

    g++ returns "undefined reference to"


    Hi

    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::Sta ndardAnalyzer()"

    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:

    $g++ -D_CL_HAVE_SYS_TYPES_H -D_CL_HAVE_PTHREAD -D_CL_HAVE_WCHAR_T -D_CL_HAVE_STDINT_H -D_CL_HAVE_INTTYPES_H -O0 -g3 -Wall -c -fmessage-length=0

    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

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    After all parts of the project have been compiled to object files they are ultimately packed together by the linker in order to form an executable.

    It is a problem at this step that gets you this error message.
    The linker already knows there has to be the compiled part for lucene::analysis::standard::StandardAnalyzer::Sta ndardAnalyzer() anywhere but he does not know where and that he has to link it in.

    You have to tell which libraries and object files are to be included.

  3. #3
    Just Joined!
    Join Date
    Aug 2004
    Posts
    6
    hi

    Thanks a lot for your help.
    I will apply what you have recommended and tell you the result.


    B.R

  4. #4
    Just Joined!
    Join Date
    Aug 2004
    Posts
    6
    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,

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Instead of -llibclucene.so, try -lclucene .
    --
    Bill

    Old age and treachery will overcome youth and skill.

  6. #6
    Just Joined!
    Join Date
    Aug 2004
    Posts
    6
    hi

    Greate!!

    Thank you so much it worked!!!!


    I was so surprised that it is working with just the name of library not the name of the file contatining it!.

    any way, Thanks again

    B.R

  7. #7
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Actually, it is not the name of the library. It's the name of the file with the initial "lib" and the extension chopped off. If the name of the file had begun with something other than "lib", then you would not have been able to use the -l option with it.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •