clang++ link failure: error: source file is not valid UTF-8?

fle*_*C0m 4 c++ linker clang++

I'm having an interesting problem. I'm compiling a toy compiler with

clang++ -g -x c++ y.tab.c lex.yy.c semantic_actions.cpp -o parser -lfl
Run Code Online (Sandbox Code Playgroud)

In y.tab.c I included semantic_actios.hpp and the contents in semantic_actions.hpp are some method declarations that are used in y.tab.c. That compiles fine.

However if I change it to

clang++ -c -g -x c++ semantic_actions.cpp -o semantic_actions.o
clang++ -g -x c++ y.tab.c lex.yy.c -o parser semantic_actions.o -lfl
Run Code Online (Sandbox Code Playgroud)

I see

semantic_actions.o:1:1: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007>
^
semantic_actions.o:1:2: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007>
    ^
semantic_actions.o:1:3: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007>
         ^
semantic_actions.o:1:4: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007>
            ^
semantic_actions.o:1:5: error: expected unqualified-id
<CF><FA><ED><FE><U+0007>
                ^
semantic_actions.o:1:6: warning: null character ignored [-Wnull-    character]
<CF><FA><ED><FE><U+0007>
// and the output goes on and on
Run Code Online (Sandbox Code Playgroud)

I must missed something very basic here. I'm on Mac OS Yosemite

$ clang++ --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)

Can someone have a look at it? Thanks!

Jos*_*ley 5

clang++ -g -x c++ y.tab.c lex.yy.c -o parser semantic_actions.o -lfl
Run Code Online (Sandbox Code Playgroud)

您要告诉Clang它的所有输入都是C ++源代码(-x c++),然后给它一个目标文件(semantic_actions.o)。Clang告诉您这semantic_actions.o不是UTF-8编码的C ++源文件。