(CNN) -- U.S. President Barack Obama arrives in South Africa on Friday for the second leg of a trip overshadowed by the deteriorating health of anti-apartheid icon Nelson Mandela.
Obama left the United States on Wednesday for Senegal, South Africa and Tanzania -- his second visit to sub-Saharan Africa since taking office.
The trip aims to bolster investment opportunities for U.S. businesses, address development issues such as food security and health, and promote democracy. It comes as China aggressively engages the continent and pours billions of dollars into Africa, replacing the United States as the continent's largest trading partner.
Following a food security event in the Senegalese capital, Dakar, on Friday, Obama will jet to South Africa.
Mandela is clinging to life at a hospital in Pretoria, an issue weighing heavily in the continent, where he retains massive popularity despite his retirement from public life.
Mandela became an international figure while enduring 27 years in prison for fighting apartheid, South Africa's system of racial segregation. He was elected the nation's first black president in 1994, four years after he was freed.
Even as he has faded from the spotlight, he remains popular and is considered a hero of democracy worldwide.
Mandela, the U.S. president said, is a hero to him and many others.
"If and when he passes from this place, one thing I think we'll all know is that his legacy is one that will linger on throughout the ages," Obama said.
He said he was inspired by what was taking place at the time in South Africa. He had read Mandela's writings and speeches, and understood "that this was somebody who believed in that basic principle I just talked about -- treating people equally -- and was willing to sacrifice his life for that belief."
Obama's visit to South Africa will include a stop at Robben Island, where Mandela spent a majority of his decades in prison. The White House schedule does not include a visit with the anti-apartheid icon.
During a news conference Thursday in Dakar, Obama called on countries worldwide to decriminalize homosexuality, a day after the U.S. Supreme Court handed a major victory to proponents of same-sex marriage by striking down a key part of the Defense of Marriage Act.
Every group of people has a right to its own views, Obama said.
"But when it comes to how the state treats people -- how the law treats people -- I believe that everybody has to be treated equal," he said.
The remarks came in response to a question from CNN's Jessica Yellin on whether he was pressing his Senegalese counterpart on the issue. Homosexuality is illegal in Senegal.
"Senegal is a very tolerant country which does not discriminate in terms of inalienable rights of human beings," Senegalese President Macky Sall said. "People are not refused jobs for being gay," he said. "But we are still not ready to decriminalize homosexuality."
After his remarks Thursday, Obama visited Goree Island, which once served as a strategic post in the transatlantic slave trade.
CNN's Josh Levs contributed to this report.