Repository: pytorch
Issue: [Libtorch/iOS] Build for iOS as dynamic library fails in linker phase. 
Labels: module: build,triaged,module: ios

🐛 Describe the bug

I'm trying to build iOS as a dynamic library. So, I openend build_ios.sh and modified this line:
```diff
 cmake "$CAFFE2_ROOT" \
     -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
     -DCMAKE_BUILD_TYPE=MinSizeRel \
-    -DBUILD_SHARED_LIBS=OFF \
+    -DBUILD_SHARED_LIBS=ON \
     ${CMAKE_ARGS[@]} \
```

Build for iOS:
```bash
BUILD_LITE_INTERPRETER=1 BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 ./scripts/build_ios.sh
```
everything worked fine until the Linking phase. It's not finding BLAS.
```bash
[100%] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/jit/backends/backend_interface.cpp.o
[100%] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/autograd/FunctionsManual.cpp.o
[100%] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/utils/out_types.cpp.o
[100%] Linking CXX shared library ../lib/libtorch_cpu.dylib
ld: warning: ignoring duplicate static library '../lib/libcpuinfo.a'
ld: warning: ignoring duplicate static library '../lib/libcpuinfo.a'
ld: warning: ignoring duplicate static library '../lib/libpthreadpool.a'
ld: Undefined symbols:
  _cblas_caxpy, referenced from:
      at::native::cpublas::axpy(long long, c10::complex<float>, c10::complex<float> const*, long long, c10::complex<float>*, long long) in CPUBlas.cpp.o
  _cblas_ccopy, referenced from:
      at::native::cpublas::copy(long long, c10::complex<float> const*, long long, c10::complex<float>*, long long) in
  _cblas_daxpy, referenced from:
      at::native::cpublas::axpy(long long, double, double const*, long long, double*, long long) in CPUBlas.cpp.o
  _cblas_dcopy, referenced from:
      at::native::cpublas::copy(long long, double const*, long long, double*, long long) in CPUBlas.cpp.o
  _cblas_dgemm, referenced from:
c10::complex<double>, c10::complex<double> const*, long long, c10::complex<double> const*, long long, c10::complex<double>, c10::complex<double>*, long long) in CPUBlas.cpp.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libtorch_cpu.dylib] Error 1
make[1]: *** [caffe2/CMakeFiles/torch_cpu.dir/all] Error 2
make: *** [all] Error 2

```


Note that the build works fine if this is not set in scripts/build_ios.sh
```diff
-    -DBUILD_SHARED_LIBS=OFF \
+    -DBUILD_SHARED_LIBS=ON \
```

#  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 13.6 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.0.40.1)
CMake version: version 3.27.7
Libc version: N/A

Python version: 3.10.13 (main, Sep 11 2023, 08:16:02) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-13.6-arm64-arm-64bit
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 M2 Pro

Versions of relevant libraries:
[pip3] numpy==1.26.2
[pip3] torch==2.1.1
[pip3] torchvision==0.16.1
[conda] numpy                     1.26.2          py310h3b2db8e_0  
[conda] numpy-base                1.26.2          py310ha9811e2_0  
[conda] pytorch                   2.1.1                  py3.10_0    pytorch
[conda] torchvision               0.16.1                py310_cpu    pytorch

cc @malfet @seemethere