finite generation of unit group of global function field Let $X/\mathbb{F}_q$ be a smooth projective geometrically connected curve. Why do we have $\Gamma(X - \{p_1,\ldots,p_n\},\mathcal{O}_X)^\times$ is finitely generated of rank $n$? (analogue of the Dirichlet unit theorem for function fields)
EDIT: 1. Is it also possible to prove this using Riemann-Roch? $\dim\Gamma(X, \mathcal{L}(D)) = \deg{D} + 1-g$?
2. Or using the exact sequence $1 \to \mathbb{G}_{m,X} \to j_*\mathbb{G}_{m,X - S} \to \bigoplus_{p \in S}\mathbb{Z} \to 0$?
EDIT2: Yes, 2. works!
 A: Denote by $U=X\setminus \{p_1, \dots, p_n\}$ and suppose $n\ge 1$. Consider the subgroup of divisors of degree $0$ on $X$:
$$H=\{ \sum_i a_i[p_i] \in \oplus_i \mathbb Z[p_i]\mid \sum_i a_i[k(p_i):\mathbb F_q]=0\}\subseteq \mathrm{Div}^0(X).$$
This is a free abelian group of rank $n-1$. 
Taking the divisors of rational functions gives a group homomorphism 
$$ \mathrm{div}: \Gamma(U, O_X)^\times \to H$$ 
whose kernel is $\mathbb F_q^\times$ because it consists in invertible regular functions on $X$. The cokernel is a subgroup of $\mathrm{Jac}(X)(K)$ 
($K$-rational points of the Jacobian of $X$) where $K$ is the compositum of the residue field $k(p_i)$. As $K$ is a finite field, $\mathrm{Jac}(X)(K)$ is finite. This implies that $\Gamma(U, O_X)^\times/\mathbb F_q^\star$ is a free abelian group of rank $n-1$. Hence 
$$\Gamma(U, O_X)^\star \simeq \mathbb F_q^\star\times\mathbb Z^{n-1}.$$ 
Here $n$ is the number of "places" at infinity. Over number fields, the corresponding number is $r_1+r_2$, the number of infinite places. 
A: In addition to @Cantlog's "geometric" answer, the Fujisaki Compactness Lemma argument via Haar measure is identical: proving for any finite separable extension $K$ of $\mathbb F_q(x)$ that ideles of norm $1$ modulo $K^\times$ is a compact group. Then as corollaries one has both finiteness of "generalized class number" and the generator-count (mod torsion) for "generalized unit groups".
That is, somehow the local compactness of the completions, the finiteness of residue class fields gives a sufficient argument.
