Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] Can't link Openfst library #4529

Closed
vzxxbacq opened this issue May 13, 2021 · 6 comments · Fixed by #4558
Closed

[CMake] Can't link Openfst library #4529

vzxxbacq opened this issue May 13, 2021 · 6 comments · Fixed by #4558

Comments

@vzxxbacq
Copy link
Contributor

vzxxbacq commented May 13, 2021

I'm developing a gst plugin with kaldi cmake, but I couldn't link openfst when I build project. So I remove CACHE option in get_filename_component in CMakeLists.txt line 185 as follow:

get_filename_component(OpenFST_LIBRARY_DIR ${OpenFST_LIBRARY} DIRECTORY CACHE)
message("OpenFST_LIBRARY: ${OpenFST_LIBRARY}")
message("OpenFST_LIBRARY_DIR: ${OpenFST_LIBRARY_DIR}  (with CACHE option)")
get_filename_component(OpenFST_LIBRARY_DIR ${OpenFST_LIBRARY} DIRECTORY)
message("OpenFST_LIBRARY_DIR: ${OpenFST_LIBRARY_DIR}  (without CACHE option)")

And the output is:

OpenFST_LIBRARY: /home/laptop/code/kaldi/tools/openfst/lib/libfst.so
OpenFST_LIBRARY_DIR:   (with CACHE option)
OpenFST_LIBRARY_DIR: /home/laptop/code/kaldi/tools/openfst/lib (without CACHE option)

I'm not sure this is a bug of kaldi, so I put the linking part in the CMakeLists.txt of custom gst plugin

set(GST_KALDI_DEPS kaldi-online2 kaldi-lat kaldi-decoder kaldi-feat kaldi-transform
        kaldi-gmm kaldi-hmm kaldi-tree kaldi-matrix  kaldi-util kaldi-base kaldi-lm
        kaldi-nnet2 kaldi-nnet3 kaldi-cudamatrix kaldi-ivector kaldi-fstext kaldi-chain)

target_link_libraries(gst-plugin-test
        ${GST_KALDI_DEPS}
        ${GST_LIBRARIES})
@vzxxbacq vzxxbacq added the bug label May 13, 2021
@kkm000
Copy link
Contributor

kkm000 commented May 14, 2021

The CMake support is very experimental, and has been written in an old, 2.x style. I'm afraid we cannot support it in general, and more so under Linux. It had been written long ago as a proof-of-concept. And we've all but dropped support for the gst plugin.

Under Linux, I suggest going normal configure and make route. You need to enable extra components in configure, IIRC, to include the login into compilation. It won't probably compile cleanly; if you come up with sensible, quality patches, please send a PR.

If you want to volunteer to improve our CMake build (the ultimate goal is to be able to use VSCode as the IDE for Kaldi), I'll appreciate that too. Some conceptual knowledge of the Modern CMake is required (google it). I commit to giving you a guidance if you want to commit to it, but right now I do not have free cycles to directly work on that by myself. A patch "improving it" in the old-CMake style has not been merged. but you may glean some pointers from it: #4481. The original author declined, as you may see.

Following the old CMake approach will be simply a wasted effort. CMake has improved dramatically since versions 2.x.

@kkm000 kkm000 added enhancement waiting-for-feedback Reporter's feedback has been requested and removed bug labels May 14, 2021
@vzxxbacq
Copy link
Contributor Author

vzxxbacq commented May 15, 2021

@kkm000 Thanks for your reply. Actually it works, we can use current CMake support to develop a plugin based on kaldi and gst with little modifications (like add -fPIC or change some vars). But as you said, it isn't intuitive to understand for me because I just learned CMake 3.x, if kaldi community is looking for a better CMake build based on 3.x, I'm happy to work on it if I can.

@danpovey
Copy link
Contributor

danpovey commented May 15, 2021 via email

@kkm000 kkm000 removed the waiting-for-feedback Reporter's feedback has been requested label May 16, 2021
@kkm000
Copy link
Contributor

kkm000 commented May 16, 2021

@vzxxbacq, thank you, sounds amazing! Could you please open a PR with your cleanup?

Whether to keep the location of OpenFST cached or not is up to you. Looking it up every cmake run costs nothing, because we exactly know where to look, so either way is fine.

@kkm000
Copy link
Contributor

kkm000 commented Jun 1, 2021

@vzxxbacq, friendly ping. If you have time share the changes that you've already implemented, we'd sure thing appreciate them!

@vzxxbacq
Copy link
Contributor Author

vzxxbacq commented Jun 8, 2021

@kkm000 sry for my late response, I've been working overtime for half a month :(

you can check the commit at fix cmake

I changed the OpenFST URL to my repo because the official repo used the absolute path in the CMakeLists.txt of the test module so that we can't use it as an external project. I have posted a PR about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants