A compactness result for differentiable functions with an application to boundary value problems