I am trying to compile the CTranslate example provided in the documentation, but it’s raising the following error. Any suggestion?
sample.cpp:3:23: fatal error: onmt/onmt.h: No such file or directory
sample.cc files looks like this:
// Create a new Translator object.
auto translator = onmt::TranslatorFactory::build("…/model_checkpoint.t7");
// Translate a tokenized sentence.
std::cout << translator->translate(“你好，世界!”) << std::endl;
I am compiling this within the CTranslate repo (https://github.com/OpenNMT/CTranslate.git)
This example is for using the library so you have to put all the include paths in the compile command with the
-I option (or better transfer them to your system’s include directory) and also link to the library. Sth like this:
g++ -o sample sample.cpp -L/yourdir/CTranslate/build -lonmt -I/yourdir/Programs/CTranslate/include/ -I/yourdir/Programs/CTranslate/build -I/yourdir/Programs/CTranslate/lib...
Thanks for the support. With those changes, compilation is smoothly compiling, but I have an errror while running the executable file. Here is the error:
./sample: error while loading shared libraries: libonmt.so: cannot open shared object file: No such file or directory.
In case this is useful, here is how I am compiling it. And the
libonmt.so file is in the directory
g++ -std=c++11 -o sample sample.cpp -L/tmp/OpenNMT-th/CTranslate/build -lonmt -I/tmp/OpenNMT-th/CTranslate/include/ -I/tmp/OpenNMT-th/CTranslate/build/ -I/tmp/tools/eigen-eigen-5a0156e40feb -I/tmp/OpenNMT-th/CTranslate/lib/ -I/tmp/OpenNMT-th/CTranslate/lib/th/ -I/tmp/OpenNMT-th/CTranslate/build/lib/TH/ -I/tmp/OpenNMT-th/CTranslate/lib/tokenizer/include/
Define the library path before your executable:
But why not use the command line tool? If you indeed want to use the library in your own application, an IDE or a cmake project would be so much easier.
It worked, thanks for the support. IDEs might or cmake might be better, but I was testing the CTransalte from command line.