Questions on making a shared library (.so) with libtorch

I’m asking this question to make sure I’m doing the right thing, as my knowledge on cmake is very limited. My purpose is to make a shared library with libtorch, so I tried a toy model based on the install libtorch example. After checking some stackoverflow answers, I found that the only thing I need to do is to change the following line in the CMakeLists.txt - Minimal Example from:

add_executable(example-app example-app.cpp)

to

add_library(example-app SHARED example-app.cpp)

(example-app.cpp needs to be changed to a library code accordingly, say changing the main function to a lib function f).
Then with the same build command in the Minimal Example:

mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..
cmake --build . --config Release

I’ll get a lib<xxx>.so that can be readily used. After that, as long as I have the libtorch/ shared libraries in my computer, I can use that shared object for the other binaries.

My question:

  1. Am I doing it in the right way?
  2. Do I have any redundant or missing steps?