For homogeneous Dirichlet boundary condition, for example $$ \left\{\!\! \begin{aligned} &-\Delta u+c(x)u=f(x),x\in\Omega\\ &u|_{\partial\Omega}=0 \end{aligned} \right. $$ The weak solution is defined as a function $u\in H_0^1(\Omega)$ satisfying $$ \int_\Omega\left(\sum_{i=1}^n\frac{\partial u}{\partial x_i} \frac{\partial v}{\partial x_i}+c(x)uv\right)\,dx=\int_\Omega fv\,dx $$ for every $v\in H_0^1(\Omega)$.
I wonder how to define weak solution for an elliptic PDE with non-zero Dirichlet boundary condition.
For example, $$ \left\{\!\! \begin{aligned} &-\Delta u+c(x)u=f(x),x\in\Omega\\ &u|_{\partial\Omega}=g \end{aligned} \right. $$
Evans's Partial Differential Equations (1st edition, Section 6.1.2) says:
... is is necessary for $g$ to be the trace of some $H^1$ function, say $w$. But then $\tilde u:=u-w$ belongs to $H_0^1(\Omega)$, and is a weak solution of the boundary-value problem $$ \left\{\!\! \begin{aligned} &-\Delta \tilde u+c(x)\tilde u=\tilde f(x),x\in\Omega\\ &\tilde u|_{\partial\Omega}=0 \end{aligned} \right. $$ where $\tilde f:=f-(-\Delta w+c(x)w)$
The problem is: how to find the function $w$, in a constructive way?
Can you please help? Thank you.