本文主要是介绍nmealib库编译提示 undefined reference to `ceil‘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、问题描述
下载了nmealib库文件,默认工程进行编译,报错,提示如下:
gcc -I include -c src/generate.c -o build/nmea_gcc/generate.o
gcc -I include -c src/generator.c -o build/nmea_gcc/generator.o
ar rsc lib/libnmea.a build/nmea_gcc/generate.o build/nmea_gcc/generator.o build/nmea_gcc/parse.o build/nmea_gcc/parser.o build/nmea_gcc/tok.o build/nmea_gcc/context.o build/nmea_gcc/time.o build/nmea_gcc/info.o build/nmea_gcc/gmath.o build/nmea_gcc/sentence.o
ranlib lib/libnmea.a
gcc -I include -c samples/generate/main.c -o samples/generate/main.o
gcc samples/generate/main.o -Llib -lnmea -o build/samples_generate
/usr/bin/ld: lib/libnmea.a(generate.o): in function `nmea_gsv_npack':
generate.c:(.text+0x729): undefined reference to `ceil'
collect2: error: ld returned 1 exit status
make: *** [Makefile:43: samples_generate] Error 1
rm samples/generate/main.o
网上搜索,因为使用了 ceil数学相关的库,说是链接需要添加 -lm 的参数。
二、解决办法
官方的 Makefile 文件
CC = gccBIN = lib/libnmea.a
MODULES = generate generator parse parser tok context time info gmath sentence
SAMPLES = generate generator parse parse_file mathOBJ = $(MODULES:%=build/nmea_gcc/%.o)
LINKOBJ = $(OBJ) $(RES)SMPLS = $(SAMPLES:%=samples_%)
SMPLOBJ = $(SAMPLES:%=samples/%/main.o)INCS = -I include
LIBS = -lm -Llib -lnmea.PHONY: all all-before all-after clean clean-custom docall: all-before $(BIN) samples all-after all-before:mkdir -p build/nmea_gccclean: clean-custom rm -f $(LINKOBJ) $(BIN) $(SMPLOBJ) $(SMPLS)doc:$(MAKE) -C docremake: clean all$(BIN): $(LINKOBJ)ar rsc $@ $^ranlib $@build/nmea_gcc/%.o: src/%.c $(CC) $(INCS) -c $< -o $@samples: $(SMPLS)samples_%: samples/%/main.o$(CC) $< $(LIBS) -o build/$@samples/%/main.o: samples/%/main.c$(CC) $(INCS) -c $< -o $@
可以看到 LIBS 已经包含了 lm 。目前的报错该怎么解决呢?解决办法:修改 LIBS 中 lm 的位置,放在后面。 如下:
LIBS = -Llib -lnmea -lm
再次编译,官方工程编译成功。
这篇关于nmealib库编译提示 undefined reference to `ceil‘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!