Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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

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

Can someone have a look at it? Thanks!

like image 654
fleetC0m Avatar asked Feb 27 '15 02:02

fleetC0m


1 Answers

clang++ -g -x c++ y.tab.c lex.yy.c -o parser semantic_actions.o -lfl

You're telling Clang that all of its inputs are C++ sources (-x c++), then you're giving it an object file (semantic_actions.o). Clang's telling you that semantic_actions.o is not a UTF-8 encoded C++ source file.

like image 142
Josh Kelley Avatar answered Oct 20 '22 00:10

Josh Kelley