Regards,
It’ll never happen, because it’s all logical and stuff, but a good solution might be to charge a fee, to be renewed annually, for a membership in the library, and refuse admission to anyone without a library ID card.
I know, the shouts of “Discrimination!” “Racism!” would be overwhelming, but it’s a sad state of affairs when a library or any institution can’t discriminate against people who loiter all day and probably pee on the floor.