JUCE and Pytorch: Reference to ‘nullopt’ is ambiguous when including libtorch

Hi, more or less new to JUCE. I am working on a standalone synth in linux with libtorch and using CMake.

I followed this project ronn/CMakeLists.txt at master · csteinmetz1/ronn · GitHub to include libtorch in the cmake file. The problem is that there is a repeated name nullopt in JUCE and libtorch that generates this error: reference to ‘nullopt’ is ambiguous. Is there a way to solve this? Thanks

JUCE/modules/juce_core/containers/juce_Optional.h:27:20: note: candidates are: ‘constexpr const std::nullopt_t juce::nullopt’
   27 |     constexpr auto nullopt = std::nullopt;
libtorch/include/c10/util/Optional.h:163:21: note:                 ‘constexpr const c10::nullopt_t c10::nullopt’
  163 | constexpr nullopt_t nullopt{0};
      |                     ^~~~~~~

Problems like that do usually arise from not using explicit namespace qualification. Looking at the error message there are two symbols juce::nullopt and c10::nullopt. The typical reason that the compiler can no longer distinguish between two such symbols is if you put a using namespace juce and using namespace c10 on top of your source files, which is considered bad practice in modern C++ for exact this reason. While you would normally write e.g.c10::nullopt which would make your intention totally clear to the compiler, you probably simply write nullopt and now the compiler no longer knows which one of the two options you refer to. In case you are using the auto generated JuceHeader.h there is an option to automatically put a using namespace juce in there which is however disabled by default for new projects for quite a while now.
Is this also the case in your project?

Thanks for the clarification. I am not sure why using namespace juce was enabled. I don’t know how the building process is working, I am using cmake from a borrowed cmake. I just deleted all the using namespace juce in the headers and now it is working. Thanks