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

Failed to compile C++ LibTorch VAD example #598

Open
fred-rabelo opened this issue Jan 18, 2025 · 2 comments
Open

Failed to compile C++ LibTorch VAD example #598

fred-rabelo opened this issue Jan 18, 2025 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@fred-rabelo
Copy link

fred-rabelo commented Jan 18, 2025

I am not a very experienced programmer, so excuse me for any simple confusion.
(running on Windows 11-64x, forgot to say)

I am trying to compile the C++ Libtorch example but running on few errors:

When i run the standard compilation line from the the readme, corrected for the location of my libtorch:

g++ main.cc silero_torch.cc -I ../../../libtorch/include/ -I ../../../libtorch/include/torch/csrc/api/include -L ../../../libtorch/lib/ -ltorch -ltorch_cpu -lc10 -Wl,-rpath,../../../libtorch/lib/ -o silero -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0

i get the following error:

At line:1 char:166
 ... lude -L ../../../libtorch/lib/ -ltorch -ltorch_cpu -lc10 -Wl,-rpath,. ...
                                                                 ~
Missing argument in parameter list.

At line:1 char:173
 ...  ../../../libtorch/lib/ -ltorch -ltorch_cpu -lc10 -Wl,-rpath,../../.. ...
                                                                 ~
Missing argument in parameter list.
     CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
     FullyQualifiedErrorId : MissingArgument

I don´t understand what argument is missing there. Any insights?

removing the Option -Wl,-rapth, :

g++ main.cc silero_torch.cc -I ../../../libtorch/include/ -I ../../../libtorch/include/torch/csrc/api/include -L ../../../libtorch/lib/ -ltorch -ltorch_cpu -lc10 -o silero -std=c++14 -D_GLIBCXX_USE_CXX11_ABI=0

it executes but returns basically the following errors:

../../../libtorch/include/torch/csrc/jit/ir/ir.h: At global scope:
../../../libtorch/include/torch/csrc/jit/ir/ir.h:302:42: error: function 'std::shared_ptr<torch::jit::Wrap<torch::jit::Value> > torch::jit::Value::wrap()' definition is marked dllimport
  302 |   TORCH_API std::shared_ptr<Wrap<Value>> wrap() {
      |                                          ^~~~
../../../libtorch/include/torch/csrc/jit/ir/ir.h:1138:42: error: function 'std::shared_ptr<torch::jit::Wrap<torch::jit::Block> > torch::jit::Block::wrap()' definition is marked dllimport
 1138 |   TORCH_API std::shared_ptr<Wrap<Block>> wrap() {
      |                                          ^~~~

and:

../../../libtorch/include/c10/macros/Macros.h:432:5: error: '__assert_fail' was not declared in this scope; did you mean '__fastfail'?
  432 |     __assert_fail(                                                       \
      |     ^~~~~~~~~~~~~
@fred-rabelo fred-rabelo added the help wanted Extra attention is needed label Jan 18, 2025
@fred-rabelo
Copy link
Author

A workaround i found for the last error "__assert_fail not declared" was adding "-DNDEBUG", supposedly turning off asserts, although i am still researching to better understand what are the implications of it.

@fred-rabelo
Copy link
Author

fred-rabelo commented Jan 19, 2025

Following the advice on this thread: https://discourse.cmake.org/t/how-to-avoid-error-definition-is-marked-dllimport/2726/13

MODULE_API’s definition was in some codepath that thought it wasn’t going to compile the definition in ModuleInterface.cpp. It is an error to have a declaration with “this comes from another library” (what dllimport means) and then provide a definition for it.

TORCH_API in this case

That solved that problem, but i am still unable to compile due to several "undefined reference to imp"

like this one:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Fred\AppData\Local\Temp\cc3lSCmS.o:silero_torch.c:(.text$_ZN5torch3jit6Object10run_methodIJEEEN3c106IValueERKSsDpOT_[_ZN5torch3jit6Object10run_methodIJEEEN3c106IValueERKSsDpOT_]+0x90): undefined reference to `__imp__ZNK5torch3jit6MethodclESt6vectorIN3c106IValueESaIS4_EERKSt13unordered_mapISsS4_St4hashISsESt8equal_toISsESaISt4pairIKSsS4_EEE'
collect2.exe: error: ld returned 1 exit status

using this command line:

g++ main.cc silero_torch.cc -I ../../../libtorch/include/ -I ../../../libtorch/include/torch/csrc/api/include -L ../../../libtorch/lib/ -ltorch -ltorch_cpu -lc10 -o silero -DNDEBUG -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants