You must ensure that code files are lexically contained entirely in a single include file. More generally, the include file does not rely on any context from its parent (except for that which is determined from the command line).
If you weave an include file, you will get a separate document for that include file which will, in general, not be linked to the master document: it will be in a separate file, named after the include file, and headings will be numbered separately.
[There is currently no simple way to require a separate source be built entirely independently so that the master document can link to it. This would be especially useful, because it would also permit time stamps to be checked and avoid unnecessary processing.]