From fa7b36d1111f1504cf215cdb1b1c61cc47bd8a6b Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 20 Apr 2026 04:16:27 -0700 Subject: [PATCH] Fix undefined reference errors for StringToVector with GCC and LTO. This CL addresses link failures when building MuJoCo with GCC and Link Time Optimization (LTO) enabled: - Declared the `StringToVector(const std::string&)` specialization in `user_util.h` to prevent the compiler from incorrectly trying to instantiate the general template. - Added an explicit instantiation for `StringToVector(char*)` in `user_util.cc` to provide the definition needed by its `const std::string&` counterpart. PiperOrigin-RevId: 902557141 Change-Id: I27b585cf1deb276d4150a5cbe6cf7e59c323a20a --- src/user/user_util.cc | 1 + src/user/user_util.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/user/user_util.cc b/src/user/user_util.cc index b7bbc00e..b98516fc 100644 --- a/src/user/user_util.cc +++ b/src/user/user_util.cc @@ -1346,6 +1346,7 @@ template<> MJAPI std::vector StringToVector(const std::string& s) { template MJAPI std::vector StringToVector(char* cs); template MJAPI std::vector StringToVector(char* cs); template MJAPI std::vector StringToVector(char* cs); +template MJAPI std::vector StringToVector(char* cs); template std::vector StringToVector(const std::string& s) { diff --git a/src/user/user_util.h b/src/user/user_util.h index 6d17fb43..b2842d85 100644 --- a/src/user/user_util.h +++ b/src/user/user_util.h @@ -264,6 +264,7 @@ template MJAPI std::string VectorToString(const std::vector& v); // convert string to vector template MJAPI std::vector StringToVector(char *cs); template MJAPI std::vector StringToVector(const std::string& s); +template<> MJAPI std::vector StringToVector(const std::string& s); } // namespace mujoco::user