JfUPDATE 1-Leaders from Cuba to Iran attending Chavez's funeral
* "He was invincible," Raul Castro says
* Body to be shown "for eternity"
* Favored successor leads in opinion polls
(Adds quotes, details, color)
CARACAS, March 8 (Reuters) - From Iran's Mahmoud Ahmadinejad to Cuba's Raul Castro, about 30 heads of state joined Friday's funeral of Hugo Chavez in a last goodbye to the charismatic but divisive Venezuelan leader who changed the face of politics in South America.
Chavez died on Tuesday at age 58 after a two-year battle with cancer, devastating millions of mostly poor supporters who loved him for putting the country's vast oil wealth at their service, but giving hope to foes who saw him as a dictator.
Huge crowds of "Chavistas" arrived early for the ceremony at a military academy where his body has been lying in state. Many were dressed in the red of the ruling Socialist Party, carrying his picture and waving Venezuelan flags.
"Chavez did not die, he multiplied!" they chanted. "Chavez lives! The revolution goes on!"
The late president's body is to be embalmed and shown "for eternity" at a military museum - similar to how communist leaders Lenin, Stalin and Mao were treated after their deaths.
His remains will lie in state for an extra seven days to accommodate the millions of Venezuelans who still want to pay their last respects to a man who will be remembered as one of the world's most colorful and controversial populist leaders.
"All these measures are being taken so that the people can be with their leader forever," said Chavez's preferred successor and acting president, Nicolas Maduro. He will be sworn in as caretaker leader after the funeral on Friday.
More than 2 million people have so far filed past Chavez's coffin behind a red rope at the grandiose military academy, many sobbing, some saluting or crossing themselves.
Among the leaders gathering in Caracas were close allies such as Ecuadorean President Rafael Correa, Brazil's current and former leaders, Dilma Rousseff and Luiz Inacio Lula da Silva, and Cuban President Raul Castro.
"Most importantly, he left undefeated," Castro said, referring to Chavez's four presidential election wins, among a string of other ballot victories in his 14-year rule.
"He was invincible. He left victorious and no one can take that away. It is fixed in history."
Belarusian President Alexander Lukashenko and Ahmadinejad were among the more controversial figures scheduled to attend the ceremony.
The United States, with whom Chavez had a rocky relationship was not sending high level officials. Former U.S. Representative William Delahunt, U.S. Representative Gregory Meeks, and the charge d'affaires from the U.S. embassy will attend, amid speculation of a possible post-Chavez rapprochement between Caracas and Washington.
"The show of love for the president has been incredible," said Foreign Minister Elias Jaua.
A government source said Chavez slipped into a coma on Monday before dying the following day of respiratory failure. The cancer had spread to his lungs, the source added.
Chavez never said what type of cancer he was suffering, and for privacy, chose to be mainly treated in Cuba.
His death paved the way for a new vote in the South American nation that boasts the world's biggest oil reserves. But it is unclear when the election will be held. Many Venezuelans have yet to get past his death and have not thought much about the future.
"For me, Chavez was more of a father than a leader," said social worker Anibal Arciniegas, 26, adding that he arrived at midnight to take his place for the funeral. "He made us visible. Before him, governments discriminated against the poor."
At the gates of the academy, activists handed out photos of Chavez along with printed quotes of his call for supporters to vote for Maduro should anything happen to him.
The constitution stipulates that an election must be called within 30 days, but politicians say the electoral authorities may not be ready and there has been talk of a possible delay.
Maduro, 50, a former bus driver who became foreign minister and then vice president, looks certain to face opposition leader Henrique Capriles, 40, the centrist governor of Miranda state who lost to Chavez in last October's election.
Opposition sources say the 30 or so political groupings making up the Democratic Unity coalition have again agreed to back Capriles, whose 44 percent vote share in 2012 was the best performance by any candidate against Chavez.
Opposition loyalists blame the late president for creating deep rifts in society with his combative, hectoring style.
"He did more damage to Venezuela than anyone else," said one opposition supporter, Cesar Caballero, 66. "The country is broken in two parts, each hates the other. Chavez did that."
A recent opinion poll gave Maduro a strong lead over Capriles, and Western investors and foreign diplomats are factoring in a probable win for Maduro and a continuation of "Chavista" policies, at least in the short term.
Maduro, who lacks Chavez's man-of-the-people charisma, has pledged to adhere to his late leader's brand of nationalist politics and leftist economic policies.
(Additional reporting by Andrew Cawthorne, Deisy Buitrao, Marianna Parraga and Simon Gardner in Caracas, and Rosa Tania in Havana; Editing by Jackie Frank)