0

I have created a project with intention of using hunspell functions in it. I am working in Ubuntu. I installed and compiled hunspell library and linked it with g++ -o wc.exe -lhunspell-1.6 wordcheck.cxx and everything seemed ok. But when I tried to compile and launch my project I got some errors.

#include <iostream>
#include "hunspell/hunspell.hxx"

using namespace std;

int main(int argc,char** argv)
{
    FILE* lst=fopen("wordlist.txt","r");
    if(!lst)
    {
        cerr<<"Can not open file\n";
        return 1;
    }
    Hunspell* hs=new Hunspell(argv[1],argv[2]);
    delete hs;
    return 0;
}

and the errors were:

/home/alex2/Документы/bO/wordcheck.cxx:14: undefined reference to Hunspell::Hunspell(char const*, char const*, char const*)' /home/alex2/Документы/bO/wordcheck.cxx:15: undefined reference toHunspell::~Hunspell()' collect2: error: ld returned 1 exit status atus

I have no idea what is wrong. I tried using

Hunspell* hs=new Hunspell();

and got that there is a candidate for it that requires three parameters:

/usr/local/include/hunspell/hunspell.hxx:115:3: note: candidate: Hunspell::Hunspell(const char*, const char*, const char*) Hunspell(const char* affpath, const char* dpath, const char* key = NULL);

The only difference is char const* and const char* but I always thought it is the same thing. The entire project is similar to the example file hunspell provides and I have no idea what am I doing wrong and why my thing is not working.

Alex
  • 1
  • 1
  • Maybe because `Hunspell::Hunspell` has three parameters, and you call it with two? – Michael May 13 '17 at 11:47
  • show us your `.pro` file content – Evgeny May 13 '17 at 19:25
  • 1. Hunspell does have a realisation with three parameters. 2. I proved that the problem is not connected with qt at all - redid the entire thing on ubuntu and I got the same problem. – Alex May 14 '17 at 00:47
  • You have included `hunspell/hunspell.hxx`, which provides your program with the hunspell API but you haven't linked the library that implements that API. See [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/q/12573816/1362568) and follow this [answer](http://stackoverflow.com/a/12574400/1362568) – Mike Kinghan May 14 '17 at 07:28
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan May 14 '17 at 07:28
  • @MikeKinghan, thanks for the answer. Does not gcc link the library with the command I used though? – Alex May 14 '17 at 08:52
  • My apologies, I didn't read carefully enough. You are linking your hunspell library before the object file that depends on it, so it is ignored. Build with `g++ -o wc.exe wordcheck.cxx -lhunspell-1.6` The answer that explains is [this one](http://stackoverflow.com/a/43305704/1362568) – Mike Kinghan May 14 '17 at 09:06

0 Answers0