Repository: pytorch
Issue: C++ standard library functions not found when compiling c10d debug handlers
Labels: oncall: distributed

### 🐛 Describe the bug

The following error was obtained when building [this](https://github.com/AnacondaRecipes/pytorch-feedstock/tree/PKG-5908-update-2.5.0) conda recipe:

```
[2009/5841] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/control_plane/Handlers.cpp.o
  FAILED: caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/control_plane/Handlers.cpp.o
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_build_env/bin/arm64-apple-darwin20.0.0-clang++ -DAT_BUILD_ARM_VEC256_WITH_SLEEF -DAT_PER_OPERATOR_HEADERS -DCAFFE2_BUILD_MAIN_LIB -DCPUINFO_SUPPORTED_PLATFORM=1 -DFLASHATTENTION_DISABLE_ALIBI -DFMT_HEADER_ONLY=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DNNP_CONVOLUTION_ONLY=0 -DNNP_INFERENCE_ONLY=0 -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DPROTOBUF_USE_DLLS -DUSE_C10D_GLOO -DUSE_DISTRIBUTED -DUSE_EXTERNAL_MZCRC -DUSE_RPC -DUSE_TENSORPIPE -D_FILE_OFFSET_BITS=64 -Dtorch_cpu_EXPORTS -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/aten/src -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/aten/src -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/onnx -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/third_party/onnx -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/nlohmann -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/api -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/api/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/caffe2/aten/src/TH -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/caffe2/aten/src/TH -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/caffe2/aten/src -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/caffe2/../aten/src -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/miniz-2.1.0 -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/kineto/libkineto/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/cpp-httplib -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/aten/src/ATen/.. -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/FXdiv/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/c10/.. -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/pthreadpool/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/cpuinfo/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/aten/src/ATen/native/quantized/cpu/qnnpack/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/aten/src/ATen/native/quantized/cpu/qnnpack/src -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/aten/src/ATen/native/quantized/cpu/qnnpack/deps/clog/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/NNPACK/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/FP16/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/tensorpipe -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/third_party/tensorpipe -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/tensorpipe/third_party/libnop/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/fmt/include -I/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/flatbuffers/include -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/build/third_party/gloo -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/cmake/../third_party/gloo -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/cmake/../third_party/tensorpipe/third_party/libuv/include -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/XNNPACK/include -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p/include/eigen3 -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/INTERFACE -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/third_party/nlohmann/include -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/caffe2 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++  -fmessage-length=0 -isystem /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p/include -fdebug-prefix-map=/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work=/usr/local/src/conda/libtorch-2.5.1 -fdebug-prefix-map=/Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_p=/usr/local/src/conda-prefix -Wno-deprecated-declarations -Wno-unknown-warning-option -Wno-error=unused-command-line-argument -Wno-error=vla-cxx-extension -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_PYTORCH_QNNPACK -DAT_BUILD_ARM_VEC256_WITH_SLEEF -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wvla-extension -Wsuggest-override -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-pass-failed -Wno-error=old-style-cast -Wconstant-conversion -Wno-aligned-allocation-unavailable -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -DUSE_MPS -Wno-unused-private-field -Wno-missing-braces -Wno-stringop-overflow -O3 -DNDEBUG -DNDEBUG -std=gnu++17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -mmacosx-version-min=11.1 -fPIC -DTORCH_USE_LIBUV -DCAFFE2_USE_GLOO -D__NEON__ -Wall -Wextra -Wdeprecated -Wno-unused-parameter -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-strict-overflow -Wno-strict-aliasing -Wunused-function -Wunused-variable -Wunused-private-field -fvisibility=hidden -O2 -Wmissing-prototypes -Werror=missing-prototypes -fopenmp=libomp -MD -MT caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/control_plane/Handlers.cpp.o -MF caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/control_plane/Handlers.cpp.o.d -o caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/control_plane/Handlers.cpp.o -c /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/distributed/c10d/control_plane/Handlers.cpp
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/distributed/c10d/control_plane/Handlers.cpp:50:8: error: no template named 'unordered_map' in namespace 'std'
    std::unordered_map<std::string, HandlerFunc> handlers_{};
    ~~~~~^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/distributed/c10d/control_plane/Handlers.cpp:37:28: error: implicit instantiation of undefined template 'std::vector<std::string>'
    std::vector<std::string> getHandlerNames() {
                             ^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_build_env/bin/../include/c++/v1/iosfwd:260:28: note: template is declared here
  class _LIBCPP_TEMPLATE_VIS vector;
                             ^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/distributed/c10d/control_plane/Handlers.cpp:40:30: error: implicit instantiation of undefined template 'std::vector<std::string>'
      std::vector<std::string> names;
                               ^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_build_env/bin/../include/c++/v1/iosfwd:260:28: note: template is declared here
  class _LIBCPP_TEMPLATE_VIS vector;
                             ^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/distributed/c10d/control_plane/Handlers.cpp:73:26: error: implicit instantiation of undefined template 'std::vector<std::string>'
  std::vector<std::string> getHandlerNames() {
                           ^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/_build_env/bin/../include/c++/v1/iosfwd:260:28: note: template is declared here
  class _LIBCPP_TEMPLATE_VIS vector;
                             ^
  /Users/dpetry/miniconda3/envs/bld/conda-bld/libtorch_1731431574707/work/torch/csrc/distributed/c10d/control_plane/Handlers.cpp:50:48: warning: private field 'handlers_' is not used [-Wunused-private-field]
    std::unordered_map<std::string, HandlerFunc> handlers_{};
                                                 ^
  1 warning and 4 errors generated.
```
I can't see an #include for unordered_map or vector in control_plane/Handlers.hpp, but I'd be surprised if this is an error in the code. are you able to please tell me what I might be doing wrong?

### Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 14.5 (arm64)
GCC version: Could not collect
Clang version: 14.0.6
CMake version: version 3.26.4
Libc version: N/A

Python version: 3.13.0 | packaged by Anaconda, Inc. | (main, Oct  7 2024, 16:25:56) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-14.5-arm64-arm-64bit-Mach-O
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Apple M1 Pro

Versions of relevant libraries:
[pip3] No relevant packages
[conda] No relevant packages

cc @H-Huang @awgu @kwen2501 @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o