Linking with kaldi libs: Undefined reference to

346 views
Skip to first unread message

Ďoďo Ivanecký

unread,
Oct 7, 2021, 8:30:43 AM10/7/21
to kaldi-help
Hi,
 I am trying to link my small app with kaldi libs. Without adding -lkaldi-XXX there is lot of errors as expected, but later they were all gone. Almost all. Whatever I add to link I always see:
/usr/bin/ld: libwrp.so: undefined reference to `fst::ReadFstKaldiGeneric(std::string, bool)'
/usr/bin/ld: libwrp.so: undefined reference to `fst::SymbolTable::ReadText(std::string const&, fst::SymbolTableTextOptions const&)'
/usr/bin/ld: libwrp.so: undefined reference to `kaldi::Input::Input(std::string const&, bool*)'

Example above was linked as follows:
g++-6 -Wall -ansi -pedantic -std=c++11  -o i_demo main.o -L../wrapper -lwrp -lpthread -L/opt/kaldi/lib -lkaldi-nnet3 -lkaldi-online2 -lkaldi-fstext

I had already all kaldi and fst libs as -l option but the 3 references are all the time missing.

any hint is welcome

thanks

Jozef 

Jan Yenda Trmal

unread,
Oct 7, 2021, 1:07:01 PM10/7/21
to kaldi-help
the gnu linker is not recursive, i.e. it's will resolve the symbols sequentially. I.e. if kaldi-fstext depends on fst libs, you will have to specify the fst libs after this library.
Or create a library group on the command line (I don't recall ATM how to do it, but should be googleable)
y.

--
Go to http://kaldi-asr.org/forums.html to find out how to join the kaldi-help group
---
You received this message because you are subscribed to the Google Groups "kaldi-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kaldi-help+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kaldi-help/413bb23f-998f-43ec-915c-4ab52167241fn%40googlegroups.com.

Ďoďo Ivanecký

unread,
Oct 8, 2021, 5:36:41 AM10/8/21
to kaldi-help
Dear Yenda, thanks for you help. 
I thought that the order is important just for the static linking. 
Anyway, I tried with -Wl,--start-group  and -Wl,--end-group but the resul is exactly the same. The 3 above mentioned symbols are undefined. Despite the fact they seem to be there.

g++-6 -o i_demo main.o -lpthread -Wl,--start-group ../wrapper/*.o /opt/kaldi/lib/lib*.so -Wl,--end-group 
/usr/bin/ld: ../wrapper/wrp.o: in function `R_Engine::Initialize(char*, char*, char*, CAudio*, int (*)(CRecognitionResult*, short, void*))':
wrp_esr.cpp:(.text+0x259a): undefined reference to `kaldi::Input::Input(std::string const&, bool*)'
/usr/bin/ld: wrp.cpp:(.text+0x272a): undefined reference to `fst::ReadFstKaldiGeneric(std::string, bool)'
/usr/bin/ld: wrp.cpp:(.text+0x27c0): undefined reference to `fst::SymbolTable::ReadText(std::string const&, fst::SymbolTableTextOptions const&)'
collect2: error: ld returned 1 exit status

In this case I passed by one auxiliary lib -namely libwrp.so - to reduce number of possible problems. But the list of missing symbol is identical.

For fst::ReadFstKaldiGeneric I checked also if the libkaldi-fstext.so was read in during the linking and was, even twice:

[pid 1248473] openat(AT_FDCWD, "/opt/kaldi/lib/libkaldi-fstext.so", O_RDONLY) = 36
[pid 1248473] openat(AT_FDCWD, "/opt/kaldi/lib/libkaldi-fstext.so", O_RDONLY) = 37

Jozef

nshm...@gmail.com

unread,
Oct 8, 2021, 10:48:22 AM10/8/21
to kaldi-help
You'd better compile libraries statically like we are doing here:

https://github.com/alphacep/vosk-api/blob/master/src/Makefile#L36

Jan Yenda Trmal

unread,
Oct 8, 2021, 11:14:19 AM10/8/21
to kaldi-help
I'm not sure. It's confusing.
 You might to need to link with kaldi-base
(or perhaps something else -- try to infer which (if any) library might be missing by grepping the functions in h files -- the directories should correspond to the libs)
y.

Ďoďo Ivanecký

unread,
Oct 8, 2021, 11:45:33 AM10/8/21
to kaldi-help
Thanks, but I asked my question because I do not want to compile statically. ;)

Ďoďo Ivanecký

unread,
Oct 8, 2021, 11:48:52 AM10/8/21
to kaldi-help
Yenda, yes you are right. It is something else. I still do not know what, but the first problem was ABI. I had it in my scripts set to 0 ...
After changing to 1 I have just 1 missing symbol:
undefined reference to `fst::SymbolTable::ReadText(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, fst::SymbolTableTextOptions const&)'

and I see it is partial success as well as as hint that way I am linking is very likely not the problem.

Jozef

Ďoďo Ivanecký

unread,
Oct 8, 2021, 12:15:39 PM10/8/21
to kaldi-help
OK, I have it. I do not yet understand why but the compilation with -isystem XXX/kaldi/tools/openfst-1.7.2/include
fixed the issue.

Reply all
Reply to author
Forward
0 new messages