An earthquake of magnitude 7.8 in Ecuador has killed at least 41 people as the government declares a national emergency.