No, that won't work. Your object o has automatic storage and is managed automatically by the surrounding scope and will be destroyed when leaving the scope. You now also have a shared pointer that has assumed ownership of it and will also try to destroy it. Your code thus has conflicting ownership over the object o.
You have to allocate the object dynamically so that you can pass the full ownership of the resource to the shared pointer.