clang ++链接失败:错误:源文件无效的UTF-8? [英] clang++ link failure: error: source file is not valid UTF-8?

查看:845
本文介绍了clang ++链接失败:错误:源文件无效的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

y.tab.c中,我包含了semantic_actios.hpp,而semantic_actions.hpp中的内容是y.tab.c中使用的一些方法声明.这样编译就可以了.

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

我知道

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

我必须在这里错过一些非常基本的东西.我在Mac OS优胜美地

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!

推荐答案

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

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

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.

这篇关于clang ++链接失败:错误:源文件无效的UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆