Bad (blank) value for _GLIBCXX_USE_CXX11_ABI

Hi,

I’m compiling against the C++ API on macOS using GCC-9.3, and cmake seems to use a bad flag:
... -fopenmp -D_GLIBCXX_USE_CXX11_ABI= -std=c++14 ... – note how it “blanks out” the _GLIBCXX_USE_CXX11_ABI variable. This causes the compiler to fail in the stdlib:

/usr/local/Cellar/gcc@9/9.3.0/include/c++/9.3.0/x86_64-apple-darwin18/bits/c++config.h:273:27: error: #if with no expression
  273 | #if _GLIBCXX_USE_CXX11_ABI

What’s probably going on here is that -D_GLIBCXX_USE_CXX11_ABI= (instead of -D_GLIBCXX_USE_CXX11_ABI=0 or -D_GLIBCXX_USE_CXX11_ABI=1) causes the compiler substitute nothing for _GLIBCXX_USE_CXX11_ABI, which means that the #if _GLIBCXX_USE_CXX11_ABI becomes #if – what we would want is #if 0

Any advice on how to fix this would be much apreciated – I’ve tried manually setting _GLIBCXX_USE_CXX11_ABI, but it seems to be overwritten somewhere.

Cheers,
Johannes

1 Like

I encountered the same problem as you, as long as torch is compiled with clang. You can modify CMakeLists.txt to specify clang++ to compile your program, then _GLIBCXX_USE_CXX11_ABI will not be added, or use gcc to compile pytorch instead of clang.

1 Like