Yes, you can use both of them, but not anywhere, as you put it.
They are both correct, but have a somewhat different emphasis.
Saying at the library emphasizes that someone or something is at that location. The speaker is thinking of the library as a point, like a point on a map.
Saying in the library emphasizes that someone or something is inside that building (as opposed to being outside).
For example, let's say I'm a student and I'm in my room back at the dormitory. Someone asks me where my roommate is. I would say:
"He's at the library."
That's the location where he currently is.
Now, let's say my roommate and I go to the library to study, and we are getting ready to leave. I exit first, and I'm standing outside the library waiting for my roommate to come out. Someone walks up to me and asks me where my roommate is. I would say:
"He's in the library."
In other words, he's still inside the building. He hasn't come outside yet.
Hope this is helpful.
Student or Learner