  Recently, linear codes constructed from defining sets have been studied
extensively. They may have nice parameters if the defining set is chosen
properly. Let $ m >2$ be a positive integer. For an odd prime $ p $, let $
r=p^m $ and $\text{Tr}$ be the absolute trace function from $\mathbb{F}_r$ onto
$\mathbb{F}_p$. In this paper, we give a construction of linear codes by
defining the code $ C_{D}=\{(\mathrm{Tr}(ax))_{x\in D}: a \in \mathbb{F}_{r}
\}, $ where $ D =\left\{x\in \mathbb{F}_{r} : \mathrm{Tr}(x)=1,
\mathrm{Tr}(x^2)=0 \right\}. $ Its complete weight enumerator and weight
enumerator are determined explicitly by employing cyclotomic numbers and Gauss
sums. In addition, we obtain several optimal linear codes with a few weights.
They have higher rate compared with other codes, which enables them to have
essential applications in areas such as association schemes and secret sharing
schemes.
