未定义的引用到Ubuntu上的c数学库 [英] Undefined reference's to c math library on ubuntu

查看:179
本文介绍了未定义的引用到Ubuntu上的c数学库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu 12.04.4 LTS服务器上编译后,我一直试图运行我的程序,但没有任何运气。注意我一直在开发我的Mac书,没有任何问题。



我已经尝试了以下数量的操作:




  • 添加-fno-builtin编译参数

  • 添加-lm编译参数(将它放在* .c之前和之后的几个不同位置文件

  • 在源代码文件中添加了#define _ISOC99_SOURCE
  • --std = gnu99而不是--std = c99

  • 添加-lt编译参数

  • 添加-Wl, - 不需要编译参数


任何人都可以与我分享我做错了什么或者我的配置中缺少什么?下面我添加了我的Makefile的内容,编译输出,gcc -v输出和输出当我尝试运行程序时。



程序输出在试图运行时:

<$ p $ (adl-main.o):在函数adl_aggregate中:
adl-main.c :( .text + 0x1d89):undefined指向` roundf'
adl-main.c :(。te (adl-calc.o):在函数adl_get_am_day_target中:
adl-calc.c :( .text + x2503) (adl-calc.o):在函数adl_pal_percentage中:
adl-calc.c :( .text + 0x787) :未定义的对`floorf'的引用
adl-calc.c :(。text + 0x790):未定义对`lroundf'的引用
collect2:ld返回1退出状态

  


这是我的make文件: #Makefile.lib

CC = gcc
AR = ar

CFLAGS =

.PHONY:all
.SUFFIXES :

ADL_SOURCES = adl-main.c adl-data.c adl-calc.c adl-fail.c adl-misc.c

all:adl-pure。 a

adl-pure.a:$(ADL_SOURCES:.c = .o)
$(AR)-rus $ @ $ ^

%.o :%.c
$(CC)-o $ @ -MMD $< -lm -std = c99 -O2 -Wall -pedantic $(CFLAGS)-c

clean:
rm -f adl-pure.a * .o * .d

-include $(ADL_SOURCES:.c = .d)

此输出它:

  gcc -o adl-main.o -MMD adl-main.c -lm -std = c99 -O2  - Wall -pedantic -fPIC -c 
gcc -o adl-data.o -MMD adl-data.c -lm -std = c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl -calc.o -MMD adl-calc.c -lm -std = c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl-fail.o -MMD adl-fail.c -lm -std = c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl-misc.o -MMD adl-misc.c -lm -std = c99 -O2 -Wall -pedantic -fPIC -c
ar -rus adl-pure.a adl-main.o adl-data.o adl-calc.o adl-fail.o adl-misc.o
ar:创建adl-pure.a

这是gcc -v的输出:

 使用内置规格。 
COLLECT_GCC = gcc
COLLECT_LTO_WRAPPER = / usr / lib / gcc / x86_64-linux-gnu / 4.6 / lto-wrapper
目标:x86_64-linux-gnu
配置为:。 ./src/configure -v --with-pkgversion ='Ubuntu / Linaro 4.6.3-1ubuntu5'--with-bugurl = file:///usr/share/doc/gcc-4.6/README.Bugs --enable -languages = c,c ++,fortran,objc,obj-c ++ --prefix = / usr --program-suffix = -4.6 --enable-shared --enable-linker-build-id --with-system-zlib - -libexecdir = / usr / lib --without-included-gettext --enable-threads = posix --with-gxx-include-dir = / usr / include / c ++ / 4.6 --libdir = / usr / lib --enable -nls --with-sysroot = / --enable-clocale = gnu --enable-libstdcxx-debug --enable-libstdcxx -time = yes --enable-gnu-unique-object --enable-plugin --enable- objc-gc --disable-werror --with-arch-32 = i686 --with-tune = generic --enable-checking = release --build = x86_64-linux-gnu --host = x86_64-linux-gnu - -target = x86_64-linux-gnu
线程模型:posix
gcc版本4.6.3(Ubuntu / Linaro 4.6.3-1ubuntu5)


解方案

此示例



 的#include<文件math.h> 
#include< stdio.h>
int main()
{
float f = 33.33f;
f = roundf(f);
printf(%f \ n,f);
return(0);

$ / code>

完全符合

  gcc -std = c99 -fno-builtin ac -lm 

相应地更改你的Makefile,你就会好的。


I've been trying to run my program after compiling on a Ubuntu 12.04.4 LTS server without any luck. Note I've been developing on my Mac book without any issues.

I've already tried the following number of things:

  • add -fno-builtin to compile params
  • add -lm to compile params (Placing it on several different places before and after *.c files
  • added '#define _ISOC99_SOURCE' to source code files
  • used --std=gnu99 instead of --std=c99
  • add -lt to compile params
  • add -Wl,--no-as-needed to compile params

Can any one share with me what I'm doing wrong? Or what missing from my configuration? Below I added the content of my Makefile, output of compiling, the gcc -v output and the output when I try to run the program.

Output of program while trying to run it:

ext/adl-pure.a(adl-main.o): In function `adl_aggregate':
adl-main.c:(.text+0x1d89): undefined reference to `roundf'
adl-main.c:(.text+0x2503): undefined reference to `lroundf'
ext/adl-pure.a(adl-calc.o): In function `adl_get_am_day_target':
adl-calc.c:(.text+0x2f8): undefined reference to `lroundf'
ext/adl-pure.a(adl-calc.o): In function `adl_pal_percentage':
adl-calc.c:(.text+0x787): undefined reference to `floorf'
adl-calc.c:(.text+0x790): undefined reference to `lroundf'
collect2: ld returned 1 exit status

This is my make file:

# Makefile.lib

CC=gcc
AR=ar

CFLAGS=

.PHONY: all
.SUFFIXES:

ADL_SOURCES=adl-main.c adl-data.c adl-calc.c adl-fail.c adl-misc.c

all: adl-pure.a

adl-pure.a: $(ADL_SOURCES:.c=.o)
        $(AR) -rus $@ $^

%.o: %.c
        $(CC) -o $@ -MMD $< -lm -std=c99 -O2 -Wall -pedantic $(CFLAGS) -c

clean:
        rm -f adl-pure.a *.o *.d

-include $(ADL_SOURCES:.c=.d)

And this the output of it:

gcc -o adl-main.o -MMD adl-main.c -lm -std=c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl-data.o -MMD adl-data.c -lm -std=c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl-calc.o -MMD adl-calc.c -lm -std=c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl-fail.o -MMD adl-fail.c -lm -std=c99 -O2 -Wall -pedantic -fPIC -c
gcc -o adl-misc.o -MMD adl-misc.c -lm -std=c99 -O2 -Wall -pedantic -fPIC -c
ar -rus adl-pure.a adl-main.o adl-data.o adl-calc.o adl-fail.o adl-misc.o
ar: creating adl-pure.a

This is the output of gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

解决方案

This example

#include <math.h>
#include <stdio.h>
int main()
{
    float f = 33.33f;
    f = roundf(f);
    printf("%f\n", f);
    return (0);
}

compiles just fine with

gcc -std=c99 -fno-builtin a.c -lm

Change your Makefile accordingly and you will be fine.

这篇关于未定义的引用到Ubuntu上的c数学库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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