The European Union wants to set up migrant "reception centres" in North Africa to process the thousands of Africans trying to reach Europe. This has been rejected by Libya, where people-smuggling networks once controlled by former strongman Muammar Gaddafi, are now able to operate freely, writes the BBC's Farouk Chothia.
As he appealed to Nato not to launch air strikes to overthrow his regime, then-Libyan leader Muammar Gaddafi said: "Now listen, you people of Nato. You're bombing a wall which stood in the way of African migration to Europe and in the way of al-Qaeda terrorists. This wall was Libya. You're breaking it."
Gaddafi was trying to exploit European fears about migration in the hope of clinging to power, but it did not work. He was killed by Nato-backed militias in October 2011 following a popular uprising against his 42-year rule.
As a result, Europe - especially Italy - lost a key partner in efforts to reduce migration from Africa.
"Not enough attention was paid to Libya after Gaddafi's overthrow," Tarek Megersi, a Libyan analyst with the UK-based European Council on Foreign Relations think-tank, told the BBC.
"There is a lack of governance structures and smuggling groups have exploited this to the maximum," Mr Megersi added.
Unlike Turkey which has stemmed the flow of migrants by agreeing to take back Syrians who reach the Greek islands in exchange for a huge financial package, Libya's weak internationally recognised government has rejected a European Union proposal to set up "reception centres" for African migrants while European states consider their asylum applications.
'We categorically reject camps for migrants,'' Libya's Deputy Prime Minister Ahmed Maiteeq said, following talks with Italy's far-right interior minister Matteo Salvini in Tripoli last week.
''It is not allowed by Libyan law," he added.
A further complication is the breakdown in law and order in Libya, where a host of rival militias are largely able to operate as they please, with some making huge amounts of money from the migrant trade.
Mr Megersi said migrants have rapidly changed the demographics of parts of Libya. The coastal city of Zawiya, which used to have a population of about 200,000, now has more than one million migrants living in it, and the surrounding area.
"They [Libyans] have the same fear as European states," he added.
Speaking after an African Union (AU) summit in Mauritania on Monday, Morocco's Foreign Minister Nasser Bourita also rejected the EU proposal, describing it as "an easy, counter-productive solution", although some poor states along the migration route - Niger is rumoured to be one of them - might eventually agree to host the "reception centres".
Gaddafi signed a "friendship" agreement with then-Italian Prime Minister Silvio Berlusconi in August 2008, in a deal which saw his regime tightening border controls - including joint maritime patrols - in exchange for Italy pledging $5bn (£3.75bn) in compensation for colonial-era crimes.
The deal led to a sharp decline in the number of people trying to reach Europe by boat - from nearly 40,000 in 2008 to 3,200 in the first seven months after joint patrols started in 2009, according to EU-funded research.
In total, 206,880 people left Libyan shores between 2003 and 2012, an average of about 23,000 a year. Almost all of them - 190,425 - went to the Italian island of Lampedusa and the remaining 16,445 to Malta, other research shows.
'Petrol and people-smugglers'
Mr Megersi said Gaddafi used migration "to hold Europe hostage", allowing smuggling networks - made up of people from the two main ethnic groups in the south-west, the Tuareg and Tebu - to thrive when it suited him.
"The tribes of southern Libya have historically been smugglers because of a lack of economic opportunities and development," Mr Megersi told the BBC.
"Gaddafi made a deal with them - smuggle goods to Niger, Chad and Algeria, rather than people to Europe. He will give them petrol or flour at subsidised prices, which they will then sell at market prices.
"The vacuum left by Gaddafi was never filled by any entity capable of exerting control or pressure over them," Mr Megersi said.
What did EU leaders agree at their summit last week?
- Exploring the possibility of "regional disembarkation platforms", designed to thwart people-smuggling gangs by processing migrants outside the EU
- Setting up secure migrant processing centres in EU countries, although no country has yet volunteered to host one. Mr Macron said France would not host one as it was not a country where migrants landed but Italian Prime Minister Giuseppe Conte said the centres could be anywhere in the EU
- Strengthening external border controls, with more funding for Turkey and countries in North Africa
- Boosting investment in Africa to help the continent achieve a "socio-economic transformation" so people no longer want to leave in pursuit of a better life in Europe
According to UN figures, about 15,151 people left North Africa - mainly Libya - by boat in 2012, which many Libyans described as the "golden year" after Gaddafi's overthrow.
In 2014, the number rose to a staggering 170,110. This was because conflict escalated between rival governments and militias jostling for power following disputed elections. The fighting was so intense that the US shut its embassy and evacuated its diplomats to neighbouring Tunisia.
In a report published last year following a study on migration trends, the UN High Commission for Refugees said: "Libya has for decades drawn people from neighbouring countries, as it offered the best employment opportunities and highest salaries in the region - although it has been increasingly roiled by instability and insecurity since the ouster of Muammar Gaddafi in 2011.
"The study found that around half of those travelling to Libya do so believing they can find jobs there, but end up fleeing onwards to Europe to escape life-threatening dangers and difficult economic conditions plus widespread exploitation and abuse."
Smuggling networks operating across East and West Africa bring the migrants by road to Libya, from countries as diverse as Eritrea - a small state which young people flee to avoid military conscription - and Nigeria, Africa's most populous state which is battling high levels of unemployment, an Islamist-led insurgency and clashes between herders and farmers.
Efforts to break up the networks in Libya and other states have yielded results.
"Certain militias [in Libya] have been given incentives to stop human-trafficking and have been co-opted into law-enforcement activities, but what these incentives are remains unclear," Mark Micallef, a Malta-based researcher with the Global Initiative Against Transnational Organised Crime think-tank, told the BBC.
Sudan - led by Omar al-Bashir, who is wanted by the International Criminal Courts for war crimes in Darfur - has also cooperated with the EU.
"Over the past two years, Sudan has been cracking down on its northern border with Chad, Libya and Egypt," Mr Micallef said.
"It has taken the opportunity to come out of isolation and engage with the international community."
Niger - which is second from bottom on the UN Human Development Index - has also "played more than its part", despite the "very big hit" this has had on the economy in its northern Agadez region, which was heavily dependent on migrants en route to Libya, Mr Micallef said.
In exchange, the EU offered 610m euros (£540m; $714m) to Niger in 2016 from a fund set up to address what it calls the root causes of "destabilisation, forced displacement and irregular migration" in 26 African states.
This included tackling population growth, "extreme poverty" and weak "economic infrastructure", the EU said on its website.
Significantly, the number of boat migrants has dropped in the first six months of this year. Less than 50,000 people arrived in Europe from North Africa, suggesting that if there is no major outbreak of violence in Libya ahead of elections scheduled for December, sea crossings in 2018 could be at their lowest since 2014.
More on the migration crisis:
For its part, the AU decided at its summit to establish the African Observatory for Migration and Development in a bid to coordinate its response to the crisis.
"Africa should not just react to decisions taken outside. We should have our own narrative," Mr Bourita, Morocco's foreign minister, told the BBC.
To curb migration, African states needed to invest in young people, who were "an energy", Mr Bourita said.
"Either you use it properly and it can be an element of development or you will not control it and it will be a problem for all the countries," he added.
'Europe need migration'
In a report published last month after a survey in nine African states, Afrobarometer, a South African-based non-governmental organisation, said the continent needed "thriving" economies to stem migration.
The desire to migrate was strongest among the young and the educated, with 43% of respondents citing the need to find a job as the main reason and 33% saying they wanted to escape economic hardship and poverty, the report said.
Most southern Africans preferred to settle in another African state, while those from West and east Africa preferred to go to Europe and North America, the report added.
Mr Megersi believes that the EU should place greater emphasis on creating legal avenues for migration in order to boost its workforce.
"Some do it for asylum. Others for economic reasons. They are young men eager and willing to work in different spheres. Europe needs migration, with its ageing population," he said.
But the current political climate in Europe mitigates against this, with many voters blaming migrants for their economic problems. This has led to the rise of right-wing parties - like Mr Salvini's League party in Italy - and efforts to curb migration are likely to intensify.
"Populists are gaining ground by holding a firm line, and you have one ad hoc measure after another. Migration policy in Europe is a game of politics," Mr Megersi added.