Condition for a compact set to be the support of a continuous function? I am studying Rudin's Real and Complex Analysis exercises and I am currently thinking about the following:

Is there a characterization of the class of compact sets of $\mathbb{R}$ which are supports of continuous functions? Is this characterization valid in other topological spaces?

For the first question, I have come to a seemingly necessary and sufficient condition on $K$, which may be a bit too complicated : $K$ is the support of a continuous function iff for all $x\in K$, for all neighborhood $V$ of $x$, there exists a nonempty open set $U\subset K\cap V$. The fact that it is necessary is pretty obvious, and for the sufficient aspect, I have considered the connected components of such a $K$, which are segments. I call a ''trivial segment'' a segment which is a singleton. Putting aside the trivial case where $K$ is empty, there is at least one nontrivial segment among the connected components of $K$. The following two cases can arise:


*

*If the number of nontrivial connected components is finite, there is no trivial segment and $f$ can be defined as a triangle-shape function on all the connected components and $0$ otherwise. $f$ is continuous and has support $K$.

*If the number of nontrivial connected components is infinite, it is countable and the nontrivial components can be ordered as $\{C_n\}_{n>0}$. On each $C_n$ $f$ is defined as a triangle-shape function of height $1/n$, and $0$ outside of $\cup_{n>0}C_n$. Again, $f$ is continuous and has support $K$.
I am now considering the extension to other spaces and I can't really figure out a way to generalize the result. The necessary condition on $K$ seems to remain valid on a general topological space, but for the other part of the proof, I have used the particular nature of the connected sets of $\mathbb{R}$, which cannot be used in the general case. Is there a way to claim a more general result, maybe involving a simpler characterization?
 A: I also come to this problem while studying Rudin's Real and Complex Analysis. I think it can be generalized as this:
suppose X is a locally compact Hausdorff space, then its compact subset K support a continuous function if and only if K exists an open subset
Proof:
(sufficiency)
suppose K exists non-empty open subset V, then by theorem 2.7 and Urysohn's lemma, there exist such a non-zero continuous function.
(necessity)
suppose f is a non-zero continuous function support by K and K does not exist a non-empty open subset, then f(K) contains more than 1 element, from Hausdorff space we know their exist an open set W which covers only part of f(K) and f-1(W) is an open set belong to K
contradiction.
A: Suppose $X$ is a normal space. $K \subset X$ is support of a continuous function $f$ if and only if there exists $V \in \Gamma(X)$, such that:

*

*$V = \cup_{n \in \mathbb{N}}F_n$, where $F_n^c \in \Gamma(X)$. i.e. $V$ is an $F_\sigma$ set.

*$K = \bar V$, i.e. $K$ is the closure of $V$.

Suppose $K$ is support of a continuous function $f$. Let $V = \{x|f(x)\not= 0\}$. $V \in \Gamma(X)$ as $f$ is continuous. We have $K = \bar V$ by definition of support. Set $F_n = \{x:|f(x)| \geq \frac{1}{n}\}$. For $n \in \mathbb{N}$, $F_n$ is closed and $V = \cup_{n \in \mathbb{N}} F_n$. Therefore $V$ is an $F_\sigma$.
Now suppose $K = \bar V$ and $V$ is an $F_\sigma$ set. Let $V = \cup _{n \in \mathbb{N}} F_n$. By Urysohn's Lemma, $\exists f_n:X \rightarrow [0,2^{-n}]$ such that $f$ is continuous, $x \in F_n \implies f_n(x) = 2^{-n}$ and $x \in V^c \implies f_n(x) = 0$.
Set $f(x) = \sum_{n=1}^\infty f_n(x)$ and $g_N(x) = \sum_{n=1}^N f_n(x)$. The functions $g_N$ are continuous and $f$ is the uniform limit of $g_N$ with $N \rightarrow \infty$. By Uniform limit theorem, $f$ is continuous. If $x \in V$, then $x \in F_n$ for some $n$,$\implies f(x) \geq \frac{1}{2^{-n}} > 0$. For $x \in V^c, f(x) = \sum_{n=1}^\infty f_n(x) = \sum_{n=1}^\infty 0 = 0$. Therefore $V = \{x|f(x)\not= 0\}$ and $K = \bar V$ is the support of $f$.
