Cross-Compiling PyTorch for Android : undefined symbol: torch::cuda::is_available()

I’m trying to cross-compile using AndroidNDK22 on Ubuntu 20.04.
I start by compiling 2 cpp files that include <torch/torch.h> using clang++ -isystem /opt/libtorch_android/headers/ -isystem /opt/libtorch_android/headers/torch/csrc/api/include/ (with other operators obviously), this goes well. However when I try to link the rest of my program into a .so and add -L/opt/libtorch_android/jni/x86_64 -ltorch -ltorch_cpu -lc10, I get these errors:

ld: error: undefined symbol: torch::cuda::is_available()
ld: error: undefined symbol: torch::nn::Module::named_buffers(bool) const
ld: error: undefined symbol: torch::nn::Module::named_parameters(bool) const
ld: error: undefined symbol: torch::nn::Module::eval()
ld: error: undefined symbol: torch::nn::EmbeddingImpl::forward(at::Tensor const&)
ld: error: undefined symbol: torch::nn::detail::RNNImplBase<torch::nn::LSTMImpl>::flatten_parameters()
ld: error: undefined symbol: torch::nn::LSTMImpl::forward(at::Tensor const&, c10::optional<std::__ndk1::tuple<at::Tensor, at::Tensor> >)
ld: error: undefined symbol: typeinfo for torch::nn::Module
[And many more]

The compiler I’m using is ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -target x86_64-none-linux-android${ANDROID_API} --sysroot=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot
The pytorch libraries I’m using come from the /script/build_pytorch_android.sh
Ultimately I run : ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -o *MYOUTPUT.so* [MYCOMPILEDOBJECTS.o] s -Wl,-soname,$(@F) -shared ${STL_LIB} -flto -no-canonical-prefixes -target x86_64-none-linux-android${ANDROID_API} -Wl,--build-id=sha1 -Wl,--no-rosegment -nostdlib++ -Wl,--no-undefined -Wl,--fatal-warnings -lgcc -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -latomic -Wl,--exclude-libs,libatomic.a -ldl -lc -lm -mfma -mavx2 -arch x86_64 -v -DANDROID_STL=c++_shared -isystem /opt/libtorch_android/headers -isystem /opt/libtorch_android/headers/torch/csrc/api/include -ltorch -ltorch_cpu -lc10 -Wl,-rpath,/opt/libtorch_android/jni/x86_64 -L/opt/libtorch_android/jni/x86_64 -L/lib64

Does anyone have any ideas as to how to solve these errors ?

After looking up the symbol’s in my libtorch_cpu.so file it would seem that torch::cuda::is_available() and the other symbols are never exported when build_pytorch_android.sh is run.
Furthermore: ${PyTorch_Source}/torch/csrc/api/src/cuda.cpp which declares this is_available() function is never compiled.