在GCC 4.6.1(Ubuntu 11.10)中链接数学库 [英] Linking Math Library in GCC 4.6.1 (Ubuntu 11.10)

查看:258
本文介绍了在GCC 4.6.1(Ubuntu 11.10)中链接数学库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的链接过程中发现问题.我没有与gcc 4.5相同.它将尝试使用以下命令链接数学库.

I find a problem in the linking process of my application. I did not have the same with gcc 4.5. It tries to link math library with the following command.

gcc -Wall -Wno-unused -MD -o mems_seektest mems_seektest.o -lm -L. -g -DASSERTS  -I../src// -I../ -I../src//src -DDEBUG -lmems_internals

并报告以下错误消息:

undefined reference to `sqrt'

有什么主意吗?

推荐答案

最近的gcc/ld使用--as-needed链接器标志作为默认值.实际上,这意味着必须在命令行上以与依赖项相反的顺序指定库.如果mems_internals库需要sqrt函数,请在-lmems_internals之后加上-lm.

recent gcc/ld uses the --as-needed linker flag as default. Practically, that means libraries have to be specified in the reverse order of dependencies on the command line. If the mems_internals library needs the sqrt function your -lm after -lmems_internals.

gcc -Wall -Wno-unused -MD -o mems_seektest mems_seektest.o  -L. -g -DASSERTS  -I../src// -I../ -I../src//src -DDEBUG -lmems_internals -lm

这篇关于在GCC 4.6.1(Ubuntu 11.10)中链接数学库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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