Home > Enterprise >  How to use WordNet in a C project?
How to use WordNet in a C project?

Time:04-28

I'm trying to link to WordNet library. I downloaded the header file (wn.h), libWN.a file and a bunch of .o files (libWN_a-search.o, etc) from WordNet. I put a main.c, wn.h and libWN.a files in a folder and implemented main.c:

#include <stdio.h>
#include "wn.h"

int main(int argc, char *argv[]) {
  char rc, *s; 

  s = "cat";
  rc = in_wn(s, ALL_POS);
  printf("rc: %d\n", rc);
  return 0;
}

I try to compile using cc main.c -L. but I get the linker error:

/usr/bin/ld: /tmp/ccvzqY4x.o: in function `main':
main.c:(.text 0x27): undefined reference to `in_wn'
collect2: error: ld returned 1 exit status

Documentation on WordNet lib can be found here. I'm just not sure what I'm doing wrong.

CodePudding user response:

Including the wn.h header file is not enough. The .h file only contains the declarations, but the actual implemenation is contained in the library file libWN.a which you failed to link with.

For linking with that library you need to tell the compiler to do so by adding -lWN:

cc main.c -L. -lWN
  • Related