Hannibal didn't bring the war elephants (the particular ones that crossed the Alps) all the way from North Africa. At the time, Hannibal raised the army from Iberia and marched from there. Iberia at the beginning of the Second Punic War was still in the hand of Carthage.

Don't know from where the elephants were first brought into Iberia though...

Annie