Global variable declared but "not declared in this scope" error

As a hobbiest programmer I learn lots by reading these questions, trying to come up with an answer, and then checking back to see if I was right and, as is often the case, why I was wrong.

I have a question about this. Wouldn't it be bad mojo to have a library that is expecting a variable to be declared external to it? Shouldn't that variable be declared in the library?

My instinct tells me to declare a private variable to the class and then add a function to the class that returns the value.

Always trying to learn more. Thanks.