private void buildAddExtRefCmd(CompoundCmd<Program> cmd, Program p, Address fromAddr,
			int opIndex,
			String extName, String path, Address addr, String label, RefType refType) {

		cmd.add(new SetExternalRefCmd(fromAddr, opIndex, extName, label, addr, refType,
			SourceType.USER_DEFINED));

		String existingPath = p.getExternalManager().getExternalLibraryPath(extName);
		if (path != null && path.length() > 0) {
			if (!path.equals(existingPath)) {
				cmd.add(new SetExternalNameCmd(extName, path));
			}
		}
	}
Add memory reference

@param fromCodeUnit
@param opIndex
@param toAddr
@param isOffsetRef
@param offset
@param refType
@return true if add was successful
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/references/ReferencesPlugin.java