C - 编译错误
Posted
技术标签:
【中文标题】C - 编译错误【英文标题】:C - compilation error 【发布时间】:2013-06-16 14:58:08 【问题描述】:如果我构建我的程序,它会给我很多错误和警告。一切都来自编译的最高源文件 - main.o。
...
./main.o:16:819: warning: null character(s) ignored [enabled by default]
./main.o:16:824: warning: null character(s) ignored [enabled by default]
./main.o:16:829: warning: null character(s) ignored [enabled by default]
./main.o:16:844: warning: null character(s) ignored [enabled by default]
./main.o:16:854: warning: null character(s) ignored [enabled by default]
./main.o:16:864: warning: null character(s) ignored [enabled by default]
./main.o:16:886: error: too many decimal points in number
./main.o:16:892: error: invalid suffix "ubuntu5" on integer constant
./main.o:16:902: error: too many decimal points in number
./main.o:16:907: warning: null character(s) ignored [enabled by default]
./main.o:16:2: error: stray ‘\24’ in program
./main.o:16:914: warning: null character(s) ignored [enabled by default]
./main.o:16:2: error: stray ‘\1’ in program
./main.o:16:924: warning: null character(s) ignored [enabled by default]
./main.o:16:2: error: stray ‘\1’ in program
./main.o:16:2: error: stray ‘\20’ in program
./main.o:16:2: error: stray ‘\1’ in program
./main.o:16:2: error: stray ‘\33’ in program
./main.o:16:2: error: stray ‘\7’ in program
./main.o:16:2: error: stray ‘\10’ in program
./main.o:16:2: error: stray ‘\220’ in program
./main.o:16:2: error: stray ‘\1’ in program
./main.o:16:935: warning: null character(s) ignored [enabled by default]
./main.o:16:2: error: stray ‘\34’ in program
./main.o:16:938: warning: null character(s) ignored [enabled by default]
./main.o:16:2: error: stray ‘\34’ in program
./main.o:16:942: warning: null character(s) ignored [enabled by default]
./main.o:16:950: warning: null character(s) ignored [enabled by default]
./main.o:16:2: error: stray ‘\16’ in program
./main.o:16:2: error: stray ‘\20’ in program
./main.o:16:2: error: stray ‘\206’ in program
./main.o:16:2: error: stray ‘\2’ in program
In file included from <command-line>:0:0:
./main.o:17:1: error: stray ‘\6’ in program
./main.o:17:1: error: stray ‘\2’ in program
....
问题可能出在哪里? 这些错误是由“-include”命令和源文件/usr/include/glib-2.0/glib/gregex.h 到makefile 引起的。但是,如果我删除这个命令,它会给我“未定义的对...的引用”的错误......来自 glib 的声明。问题在于使用 glib。在我尝试之前(没有效果):
INCLUDES = -I/usr/include/glib-2.0 \
-I/usr/include/glib-2.0/glib
LIBS := -lglib-2.0
有没有人用 glib 有正确的 makefile 命令?谢谢
编辑:我想创建一个程序,使用 streamripper 录制互联网音频流。
CC = gcc
CFLAGS = -g -Wall $(shell pkg-config --cflags glib-2.0) -D__UNIX__
LFLAGS = -L/usr/include/x86_64-linux-gnu \
-L/usr/local/lib/ \
-L/usr/include/x86_64-linux-gnu
SRCS = main.c \
streamripper.c #\
/usr/include/glib-2.0/glib/gregex.h
OBJS = $(SRCS:.c=.o)
MAIN = radio
INCLUDES = -I/home/honza/workspace/Radio_processing/streamripper/libmad-0.15.1b \
-I/usr/include \
-I/usr/include/x86_64-linux-gnu \
-I/usr/include/x86_64-linux-gnu/4.6/include \
-I/usr/include/x86_64-linux-gnu/4.6/include-fixed \
-I/usr/local/include \
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
-I/usr/lib/x86_64-linux-gnu/glib-2.0 \
-I/usr/include/glib-2.0 \
-I/usr/include/glib-2.0/glib
LIBS := -lm libmad.a libstreamripper.a -glib -lglib-2.0 \
$(shell pkg-config --libs glib-2.0)
#-lavcodec -lavutil -lavformat -lpthread
all: $(MAIN)
@echo 'My makefile finished'
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
【问题讨论】:
发布您的来源,否则我们无法帮助您。*.o
不是源文件,它们是目标文件,已经编译。你不能再次编译它们。
您以某种方式强制编译器将 main.o
(而不是 main.c
)解释为 C 程序。
发布您的 makefile 或构建脚本
您的源文件中似乎包含无效字符......
源文件没问题,我查过了。 Eclipse 这显示在编辑器中。
【参考方案1】:
一切都来自编译的最高源文件 - main.o
再次编译目标文件,或者将源文件命名为目标文件,这很奇怪。
.o 通常是来自 .c 文件的编译步骤。
【讨论】:
我的英语有点问题。我将 main.c 构建到 main.o,然后在终端打印错误和警告。以上是关于C - 编译错误的主要内容,如果未能解决你的问题,请参考以下文章