Yes, both are correct.
'In' emphasises the idea of being inside a particular space: within a room or set of rooms. You'd certainly say this if the library referred to is a room within your school building, for example. You lost your card in the library, not in the science lab.
'At' is an entire location in a town, neighbourhood or campus. If you're thinking of the library as an independent building/ facility, you'd use 'at'. You lost your card at the library, not at the football stadium.