In this work, we consider rational ordinary differential equations dy/dx = Q(x,y)/P(x,y), with Q(x,y) and P(x,y) coprime polynomials with real coefficients. We give a method to construct equations of this type for which a first integral can be expressed from two independent solutions of a second-order homogeneous linear differential equation. This first integral is, in general, given by a non Liouvillian function. We show that all the known families of quadratic systems with an irreducible invariant algebraic curve of arbitrarily high degree and without a rational first integral can be constructed by using this method. We also present a new example of this kind of families. We give an analogous method for constructing rational equations but by means of a linear differential equation of first order.