Officials said the empty building was being occupied by two families.
Speaking about the fatalities, Lopez said they were two adults, a baby and a three-year-old. Four people had survived the blaze but were treated for smoke inhalation, he added.
Many abandoned buildings in Barcelona are illegally occupied by homeless people. In December last year, several died in an abandoned warehouse occupied by squatters in Badalona, a Barcelona suburb.
Lopez said the cause of the fire was not yet known and police were investigating.