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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unefined reference to C10::Error::Error when linking against libTorch #13541

Closed
ShahriarSS opened this issue Nov 3, 2018 · 10 comments

Comments

Projects
None yet
8 participants
@ShahriarSS
Copy link

commented Nov 3, 2018

馃悰 Bug

Hi
I just dowloaded libTorch to work with the C++ API of pytorch. I tried to link against it in qt creator and include <torch/torch.h> but ran into an error. Here it is:

error: undefined reference to `c10::Error::Error(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void const*)'

I thought that the problem was that I didn't link against c10 but after I did that the error still remained.

here is how I link against libTorch in my .pro file:
INCLUDEPATH += $$PWD/include
INCLUDEPATH += $$PWD/include/torch/csrc/api/include

LIBS += -L$$PWD/lib

LIBS += -ltorch -lnvrtc -lc10
LIBS += -lcudnn -lcuda -lcudart -lcublas -lcurand -lcusolver

Here $$PWD/ is the path to libTorch directory.

I know that i can use cmake but I didn't try that. I want to be able to use pytorch with qmake system because it is easier and more clean to work with.
My OS is Fedora 28 and I have CUDA 9.2 installed on my system

@ezyang

This comment has been minimized.

Copy link
Contributor

commented Nov 4, 2018

You probably have a C++ ABI problem; maybe your compiler is too old. What version of gcc are you using?

@ezyang

This comment has been minimized.

Copy link
Contributor

commented Nov 4, 2018

@ShahriarSS

This comment has been minimized.

Copy link
Author

commented Nov 4, 2018

@ezyang

c++ (GCC) 8.2.1 20181011 (Red Hat 8.2.1-4)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@zou3519 zou3519 added the module: cpp label Nov 5, 2018

@goldsborough

This comment has been minimized.

Copy link
Contributor

commented Nov 6, 2018

I think you're missing "-D_GLIBCXX_USE_CXX11_ABI=0" in your build flags. We provide this in our TorchConfig.cmake, which is why we recommend cmake as the easiest way to build LibTorch. That said, you can add that to your QtCreator config. See https://github.com/pytorch/pytorch/blob/master/cmake/TorchConfig.cmake.in for the relevant file

Please let me know if that fixes the issue.

@ShahriarSS

This comment has been minimized.

Copy link
Author

commented Nov 7, 2018

@goldsborough
Thank you that fixed the problem. Here is how to apply the flag for those who have the same problem:
QMAKE_CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0

@ShahriarSS ShahriarSS closed this Nov 7, 2018

@sky-fun

This comment has been minimized.

Copy link

commented Nov 19, 2018

@goldsborough what should i do if i need to use libtorch in my project which must set "-D_GLIBCXX_USE_CXX11_ABI=1" ? anything suggestion锛

@goldsborough

This comment has been minimized.

Copy link
Contributor

commented Nov 26, 2018

@sky-fun compile PyTorch from source

@libichong

This comment has been minimized.

Copy link

commented Mar 4, 2019

@goldsborough How can i use the flag in msbuild? Do you have any suggestion

@martinruenz martinruenz referenced this issue Mar 9, 2019

Closed

cuda error #17834

@martinruenz

This comment has been minimized.

Copy link

commented Mar 12, 2019

@goldsborough
Similar to @sky-fun I would like to set -D_GLIBCXX_USE_CXX11_ABI=1. However, when I compile pytorch myself (-D_GLIBCXX_USE_CXX11_ABI=1 is default on my platform) I keep running into a typical ABI related error:

c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'

On one of the platforms I tested the error appeared at runtime, on another platform at compile-time. (Which is also kind of weird)

Is there a flag that I am missing? It seems that c10 is not build with the new ABI, whilst the rest is? Since c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) looks like a missing C++11 ABI definition.

@Kuldaen

This comment has been minimized.

Copy link

commented May 13, 2019

We are getting this problem too. It is not an abi issue. The cxx11 namespace only applies to std:: eg. std:: basic_string. Looking at libc10.so it seems this constructor is missing altogether

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.