Conflict between libtorch and libboost, libtorch and Apache arrow


I’m trying to build a training program with libtorch and libboost. But it seems libtorch has conflicts with libboost. The following example has segmentation fault at libtorch’s both CPU version and CUDA version. Here are files. Did I make any mistake in CMakelists?

Apache arrow also has similar issues. It will have compile errors when I import “torch/torch.h” and arrow related header files together.

Will your program success if you remove all the libtorch related stuff from CMakeLists.txt?
Which version of libtorch? Can you post your error message (stack)?

Yes. The program will execute when I removed libtorch from the CMakelists.
I tested on libtorch version on cu102 1.8.0.dev20201207 + boost version 1.67 and on cpu 1.8.0.dev20201221 + boost version 1.72.

The segmentation fault happens on here and the error message is
“Program received signal SIGSEGV, Segmentation fault.
0x00007ffff79b6b10 in boost::filesystem::path::m_append_separator_if_needed() () from /usr/lib/”

I can’t post Arrow errors here because there are too many (500+). But when I removed the “torch/torch.h”, it can compile successfully.

Similar issues also happen on RocksDB. See comments in this file. Did I make any mistake?
Or this issue may be caused by “GLIBCXX_USE_CXX11_ABI” flag.

The issue is because of -D_GLIBCXX_USE_CXX11_ABI=0 flag. Here is the related disscusion. Everything is fine when I download the [] version.

But the conflict between Arrow and libtorch is still there.

We have 2 versions of libtorch available on one is ABI version, we also has a pre-abi version which is compiled with -D_GLIBCXX_USE_CXX11_ABI=0.
You can download the pre-abi version and compile everything else with -D_GLIBCXX_USE_CXX11_ABI=0. Does that works for you?

Yes. This solves the liboost conflict. But I still can’t use Apache arrow with libtorch.

I never use arrow with libtorch. If your compile error is 500+ lines, can you put it into or similar? I can take a look at, but can not guarantee I have the solution though :slight_smile:

I think it’s because libtorch and Arrow have some same micros.
Currently, I bypass the issue by separating the project into two parts.
Here is the error after I add the “#include <parquet/file_reader.h>” in my file.

The duplicated file is c10/util/variant.h vs /usr/include/arrow/vendored/variant.hpp

I think they both twisted from boost lib.
MPARK_LIB_HPP is defined in c10/util/variant.h first, so the code block for MPARK_LIB_HPP won’t be included from /usr/include/arrow/vendored/variant.hpp. That’s why you have so many lib is not declared.
I think probably separate into 2 parts is the correct way given this situation.