为什么我要明确地联系起来的libm? [英] Why do I have to explicitly link with libm?

查看:224
本文介绍了为什么我要明确地联系起来的libm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  为什么你需要数学库​​的链接C 3

当我写的使用功能从文件math.h 库的程序,那为什么我必须明确地链接到的libm ,即使他们是C标准库的一部分?

When I write a program that uses functions from the math.h library, why is it that I have to explicitly link to libm even though they are part of the C standard library?

比如,当我想用​​罪()的功能,我需要的#include<文件math.h> ,但我也需要通过 -lm 到GCC。但是,对于从标准库中的任何其他图书馆,我没有这样做。为什么会不同?

For instance, when I want to use the sin() function I need to #include <math.h> but I also need to pass -lm to GCC. But for any other library from the standard library, I don't have to do that. Why the difference?

推荐答案

在过去,连接器是缓慢和分离其余大多未使用的数学code做编译过程更快。今天差别不是那么大,所以你可以在 -lm 选项添加到默认的编译器配置。

In the old days, linkers were slow and separating the mostly unused math code from the rest made the compilation process go faster. The difference is not so great today, so you can add the -lm option to your default compiler configuration.

请注意,该头&LT;&MATH.H GT; (或任何其他头)不包含code。它包含有关code的信息,特别是如何以调用函数。在code本身是在库中。我的意思是,你的程序不使用的&LT;文件math.h&GT; 的,它使用数学库,并​​使用声明的原型在&LT;文件math.h方式&gt;

Note that the header <math.h> (or any other header) does not contain code. It contains information about the code, specifically how to call functions. The code itself is in a library. I mean, your program does not use the "<math.h> library", it uses the math library and uses the prototypes declared in the <math.h> header.

这篇关于为什么我要明确地联系起来的libm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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