President Trump recommended building a wall across the Sahara to solve Europe's migrant crisis, Spain's foreign minister says.
Josep Borrell, also a former President of the European Parliament, disagreed with the strategy.
The comments came during a visit Mr Borrell made to the US at the end of June.
Mr Trump's pledge to build a wall between the US and Mexico was one of his best-known election promises.
Mr Borrell recounted his conversation with the US president at a lunch event in Madrid this week, Spain's foreign ministry confirmed to the BBC.
"The border with the Sahara cannot be bigger than our border with Mexico," Mr Borrell quoted Mr Trump as saying.
The US-Mexico border is 1,954 miles (3,145 km) long. The Sahara desert stretches for 3,000 miles.
Spain has no sovereignty over the Sahara, but it does possess two small enclaves on the north African coast, Ceuta and Melilla, separated from Morocco by controversial wire fences.
The enclaves have become magnets for African migrants seeking a better life in Europe and refugees fleeing persecution and conflict.
Since January of this year, at least 35,000 undocumented migrants have arrived in Spain, the highest number received by any Mediterranean EU country.
However, Germany - the most popular EU destination for migrants - has been registering more than 10,000 asylum-seekers a month this year.