When going for a wonder such as the Great Library or Great Lighthouse (G Lighthouse being much more important than anything else in some games), very early prebuilds are important. Not essential in all games, but they are in most.
If you start with alphabet (commercial), then go straight for a 40-turn writing. If the tech rate is high enough you can forget a 40-turn Literature or Map Making stint as the wonders may be gone by then. Normally, you can do a 40-turn research, and time your pre-build to coincide with getting the tech.
When other civs get the tech, you need to either be sure there are no wonder cascades happening by the AI, or you need to be ready to build it. On a fast-tech game you really need the prebuild done correctly, so you only have a few turns before triggering it. On a low-tech game, you normally have 20 or 30 turns before the AI can build the wonder, because they start from scratch and need 400*0.6=240 shields for the Great Library, and only 180 for the Great Lighthouse (IIRC, cos I'm at work).
If you don't have full contacts, remember that they may be building wonders without your knowledge, with a full set of contacts it is much easier.
But as others say, ancient wonders can be easily captured. Spending so much focus in the ancient era can hold you back. Personally, I tend to go for the Great Lighthouse when I am on an island, and I go for the Great Library usually when I an commercial or if I get an early free settler, to compensate for the production loss.