简体   繁体   中英

Errors while using Libtorch + OpenCV + QT Creator

I have the following configuration in the .pro file

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += thread

SOURCES += main.cpp

INCLUDEPATH += /usr/local/include/opencv4
LIBS += -L/usr/local/lib/
LIBS += -lopencv_core
LIBS += -lopencv_highgui
LIBS += -lopencv_imgproc
LIBS += -lopencv_videoio

QMAKE_CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0

INCLUDEPATH += /path/to/libtorch/include
INCLUDEPATH += /path/to/libtorch/include/torch/csrc/api/include
LIBS += -L/path/to/libtorch/lib
LIBS += -ltorch -lc10

OpenCV works absolutely fine without "QMAKE_CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI= 0 ". With this, however, I get this following errors:

在此处输入图像描述

OpenCV works fine with "QMAKE_CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI= 1 " as well. But it throws a different set of errors:

在此处输入图像描述

Setting "QMAKE_CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI= 0 " has been recommended for Libtorch in most of the forums to avoid the errors above.

What could be a solution or some solutions to work around this? (I am a newbie to both Libtorch and Qt Creator.)

Maybe OpenCV and Libtorch were compiled with a different version of GCC (and different values of _GLIBCXX_USE_CXX11_ABI).

Try recompiling them by yourself and see if things change.

The problem is that you downloaded the wrong ABI version of LibTorch . It looks like that you downloaded the Pre-CXX11 ABI version of LibTorch and OpenCV is compiled with CXX11 ABI . So if you set _GLIBCXX_USE_CXX11_ABI=0 , OpenCV throws errors, and if you set _GLIBCXX_USE_CXX11_ABI=1 , LibTorch throws errors.

Download the CXX11 ABI LibTorch from PyTorch official website and you won't need to set the _GLIBCXX_USE_CXX11_ABI flag.

选择 CXX11 ABI

About the dual ABI problem of GCC, see https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM