Python Implementation of Track-to/aim constraint
I can't explain the math to do it manually, but you can use python to create a constraint that will do the rotation for you. You can then apply the visual transform and delete the constraint if you don't want to leave it there.

targetobj = bpy.data.objects['Sphere']
pointyobj = bpy.data.objects['Cone']

ttc = pointyobj.constraints.new(type='TRACK_TO')
ttc.target = targetobj
ttc.track_axis = 'TRACK_Z'
# we don't care about the up_axis
# but default is Z and it needs to be different that track_axis
ttc.up_axis = 'UP_X'

bpy.ops.object.select_all(action='DESELECT')
pointyobj.select = True
bpy.ops.object.visual_transform_apply()

pointyobj.constraints.remove(ttc)


Not sure if it will help but I believe the trackto_evaluate function currently on line 965 of constraint.c is the math behind the constraint.