Static build throws exception during static initialization

I built libtorch with static libs and when I run my app I get the following:

terminate called after throwing an instance of 'c10::Error'
  what():  Could not find schema for aten::empty.memory_format
Exception raised from findSchemaOrThrow at ../aten/src/ATen/core/dispatch/Dispatcher.cpp:81 (most recent call first):
frame #0: std::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > ()>::operator()() const + 0x13 (0x300844f in ./bin64/SA)
frame #1: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x2f (0x3007cc1 in ./bin64/SA)
frame #2: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x59 (0x3006ce2 in ./bin64/SA)
frame #3: c10::Dispatcher::findSchemaOrThrow(char const*, char const*) + 0x16c (0xb34a1c in ./bin64/SA)
frame #4: ./bin64/SA() [0x1063ccb]
frame #5: at::_ops::empty_memory_format::call(c10::ArrayRef<long>, c10::optional<c10::ScalarType>, c10::optional<c10::Layout>, c10::optional<c10::Device>, c10::optional<bool>, c10::optional<c10::MemoryFormat>) + 0x58 (0x10bcf0e in ./bin64/SA)
frame #6: at::empty(c10::ArrayRef<long>, c10::TensorOptions, c10::optional<c10::MemoryFormat>) + 0x11b (0xa94b7b in ./bin64/SA)
frame #7: ./bin64/SA() [0xa96e23]
frame #8: ./bin64/SA() [0xa97b89]
frame #9: ./bin64/SA() [0xa3543a]
frame #10: __libc_csu_init + 0x4d (0x39199ad in ./bin64/SA)
frame #11: __libc_start_main + 0x78 (0x7f301bfecc18 in /lib/x86_64-linux-gnu/libc.so.6)
frame #12: _start + 0x2a (0xa7dc5a in ./bin64/SA)

I’ve include the “whole archive” (ie. -Wl,–whole-archive) for libtorch.a and libtorch_cpu.a .

pytorch-v1.12.1
Ubuntu 18
GCC 8.5.

I’m guessing libtorch has 1 or more pre-built operators that are supposed to be loaded during initialization, but are not. Does that seem right? Any pointers where that code sits?

By the way, a simple app like this builds and runs fine:

const auto tensor = torch::eye(3);
std::cout << tensor << '\n';

I am having this same error on mobile. Did you ever find a solution?

@codesniffer13 did you ever find the solution for this ?

@sjmerel2 , @Bilahari_Akkiraju - I confirmed the approach suggested by user VariantXYZ at https://github.com/pytorch/pytorch/issues/14367#issuecomment-1258320460 works. I never completed the solution though.

It’d be great if someone can complete it and either merge it into mainline or make it available for others.