Programmatically link files to (global-config enabled) QM test cases?
Accepted answer
Currently, there is no public API to create links between EWM (RTC) files and test cases, so you would need to use the GUI. This is obviously a gap, so I'd recommend submitting an enhancement request asking for this functionality to be exposed via a public API. Note: There of course is an internal API to do so, so if your need is urgent, you could try that with the usual caveat that internal APIs are subject to change in future releases.
2 other answers
The ELM offering provides links between requirements, change requests, and test cases: requirements are implemented by change requests and validated by test cases. Any defects discovered are captured as RTC work items. Links from these lifecycle artifacts are not typically to specific source files, but rather change sets that record the actual work done. Developers would associate their change sets with work items before delivering the work to a shared stream. This links the files changed in the change set with the associated work item, which could then be linked to requirements and test cases as needed.