Are there any libraries (preferably open-source) for parsing AutoCAD files (DWG or DXF)?
Well, For the DXF file format the specification is available online so you can write your own parser for this file format the document can be found here: http://images.autodesk.com/adsk/files/acad_dxf0.pdf
But if you don't want to you can use libdxf an open source library to parse dxf files but according to the developer it's a “Work in progress” you can find it here: https://github.com/bert/libdxf or you can install it in ubuntu using command:
sudo apt-get install libdxflib-dev
Also another library that is provided by coin3d (can be used separately) is named dime and is probably the one used by freecad can be found here: https://bitbucket.org/Coin3D/dime It also can be installed in ubuntu using the following command:
sudo apt-get install libdime-dev
For the DWG format you can use libredwg library it's from opensource foundation and you can find it here: http://www.gnu.org/software/libredwg/
But please note that according to Wikipedia it has licensing issues of its own. http://en.wikipedia.org/wiki/LibreDWG
A fork of libredwg is available under the name libDWG it is able to read DWG file formats R13, R14, R2000 and R2004 and can be found at : http://libdwg.sourceforge.net/en/ I tested the library and the problem is that most of the sample files online have a newer version than the library can load which is not very practical.
Another good page (with some code samples) of how to read autocad files can be found at ibm website here: http://www.ibm.com/developerworks/opensource/library/os-autocad/
Bottom line is using dxf is the better option since it's open and can be supported the dwg support can't be easily done.