Let $D$ be a star domain and $a_1, \dots, a_n \in D$. I want to show that a holomorphic function $f: D\setminus\{a_1, \dots, a_n\} \rightarrow \mathbb{C}$ has a primitive if and only if $\text{res}_{z=a_i} f = 0$ for all $i \in \{1, \dots, n\}$.
I already got the first implication:
$"\implies"$: We have for sufficiently small $r > 0:$ $$\text{res}_{z=a_i}f=\int_{|z-a_i|=r}f(z)\,\text{d}z$$ And $f$ has a primitive this integral vanishes.
Sadly I'm stuck proving the second implication and don't know where to start.
Choose an arbitrary fixed $z_0 \in D$ and define $$F(z) = \int_{z_0}^z f(w) \, dw$$ for $z \in D$, where the integration is done along an arbitrary path $\gamma$ connecting $z_0$ with $z$ in $D$. Use the residue theorem to show that the the definition is independent of the choice of $\gamma$, so that $F$ is well-defined.
Finally show that $F' = f$: Let $z_1 \in D$ and $\epsilon > 0$. There is a $\delta > 0$ such that $B_\delta(z_1) \subset D$ and $|f(w) - f(z_1)| < \epsilon$ for all $w \in B_\delta(z_1)$. Then for all $z_2 \in B_\delta(z_1)$ with $z_2 \ne z_1$ $$ \frac{F(z_2) - F(z_1)}{z_2 - z_1} = \frac{1}{z_2 - z_1}\int_{[z_1, z_2]} f(w) \, dw = \int_0^1 f(z_1 + (z_2 - z_1) t) \, dt $$ and therefore $$ \left| \frac{F(z_2) - F(z_1)}{z_2 - z_1} - f(z_1) \right| \le \int_0^1 \bigl|f(\underbrace{z_1 + (z_2 - z_1) t}_{\in B_\delta(z_1)}) -f(z_1)\bigr|\, dt \le \varepsilon \, . $$