WLOG, take $u : M’ \to M$ to be the inclusion of a submodule.
Consider the partial order $(S, \leq)$ defined by $S = \{(W, g) \mid W$ is a submodule of $M$, $g : W \to Q$ is $R$-linear$\}$ and $(W, g) \leq (X, h)$ if and only if both $W \subseteq X$ and $h|_W = g$.
Note that every chain of $S$ has a least upper bound. In particular, if $C$ is a chain in $S$, then let $W = \{0\} \cup \bigcup\limits_{(X, h) \in C} X$ and define
$$g(x) = \begin{cases}
h(x) & x \in X, (X, h) \in C \\
0 & x = 0
\end{cases}$$
Then $W$ is a submodule of $M$, $g$ is a well-defined linear map $g : W \to Q$, and $(W, g)$ is an upper bound of $C$.
Now recall the following version of Zorn’s Lemma:
Let $(S, \leq)$ be a poset, and suppose every chain in $S$ has an upper bound. Then for all $x \in S$, there is a maximal element $x \leq m \in S$.
Applying this version of Zorn’s Lemma with $x = (M’, f)$ gives us some maximal $(W, g) \in R$ with $M’ \subseteq W$ and $g|_{M’} = f$. It now suffices to prove that $W = M$.
Consider an arbitrary $x \in M$. Let $I = \{r \in R \mid rx \in W\}$. Then $I$ is an ideal. Note that the map $h(r) = g(rx)$ is an $R$-module homomorphism $h : I \to Q$. Extend this to an $R$-module homomorphism $\tilde{h} : R \to Q$.
Now define $X = W + (x)$, and define $i : X \to Q$ by $i(w + rx) = g(w) + \tilde{h}(r)$ whenever $w \in W$, $r \in R$. Verify that $i$ is well-defined and $R$-linear. Then $(W, g) \leq (X, i)$. Since $(W, g)$ is maximal, we have $W = X$ and thus $x \in W$.
Therefore, $W = M$. So $g = \tilde{f}$ is the function we require.
Finally, note that we do require Zorn’s Lemma (or at least some form of the axiom of choice) to show (2) implies (1). This is because we can show without choice that $\mathbb{Q}$ is an injective $\mathbb{Z}$-module using definition (2), but we cannot show this using definition (1). See my answer here.