I have not found a way to do this using cairo libraries. But this is a feature that I was looking for too. It would be definitely useful when (for example) stroking a combination of two paths - the linkers mentioned by ntd seem to be unable to do this.
In the meantime, I'm trying to write scripts for inkscape and let inkscape do the merging / distinction. Acceptable for the problem I'm working on, but definitely not for you. Are you lucky, either with Cairo or with any other svg library? After a couple of days of searching the Internet, this doesn't seem trivial: /
source
share