The example in the Codex assumes that you are embedding wordpress directly into your page template.
A lot of people need to integrate such wordpress functionality into a CMS or using a PHP framework. This usually means that the example code is added inside a function. The error only occurs when trying to include wordpress from inside a function (something needs to have global scope?).
I’ve been looking around for a solution, but haven’t found one anywhere. I did find this related big report though – it’s been assigned to 3.0:
https://core.trac.wordpress.org/ticket/11066