diff --git a/torchaudio/csrc/sox/stub.cpp b/torchaudio/csrc/sox/stub.cpp index 0b390b832e2..c83b6d3c440 100644 --- a/torchaudio/csrc/sox/stub.cpp +++ b/torchaudio/csrc/sox/stub.cpp @@ -16,11 +16,11 @@ class StubImpl { StubImpl(const char* name) : handle(name) { // check version: we only support 14.4.2 { - auto version = ((const char* (*)(void))handle.sym("sox_version"))(); - TORCH_CHECK( - strcmp(version, "14.4.2") == 0, - "Need libsox 14.4.2, but found ", - version); + auto f = (const sox_version_info_t* (*)())handle.sym("sox_version_info"); + if (SOX_LIB_VERSION_CODE != f()->version_code) { + auto ver = ((const char* (*)())handle.sym("sox_version"))(); + TORCH_CHECK(false, "Need libsox 14.4.2, but found ", ver); + } } // Register fanction pointers on public-facing interface @@ -60,24 +60,18 @@ class StubImpl { } } }; - -static std::unique_ptr _stub; - } // namespace #if defined(_WIN32) -#define EXT ".lib" +#define EXT "lib" #elif defined(__APPLE__) -#define EXT ".dylib" +#define EXT "dylib" #else -#define EXT ".so" +#define EXT "so" #endif LibSoxStub& libsox_stub() { - static c10::once_flag init_flag; - c10::call_once(init_flag, [](){ - _stub = std::make_unique("libsox" EXT); - }); - return _stub->stub; + static StubImpl s{"libsox." EXT}; + return s.stub; } #undef EXT