为什么math.h需要链接到makefile中而不是string.h中? [英] Why does math.h need to be linked in makefile but not string.h?

查看:98
本文介绍了为什么math.h需要链接到makefile中而不是string.h中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直到处都包含< string.h> ,而当我去为 pow包含< math.h> 的那一刻()我发现我需要修改makefile才能访问 pow 的定义.

I've been including <string.h> all over the place and the moment I go to include <math.h> for pow() I discover that I need to modify my makefile to get access to the definition of pow.

如果需要包含更多库,我也不知道在哪里可以查找更多库.我随机读取了 -lm 标志(或至少是它的 m )指示标准c数学库,但是我不知道还有什么其他标准c库可能会被称为.

I also do not know where I can look up more libraries if I need to include them. I randomly read that -lm flag (or at least the m of it) indicates the standard c math library, but I have no idea what any of the other standard c libraries might be called.

我只是查看了 user/local/lib ,而我看到的是:

I just looked in user/local/lib and all I see is:

$ cd /usr/local/lib
$ ls -al
drwxr-xr-x  3 root root  4096 Apr 25  2012 .
drwxr-xr-x 10 root root  4096 Apr 25  2012 ..
drwxrwsr-x  4 root staff 4096 Oct 14 10:19 python2.7

推荐答案

string.h 是对标准库模块的标头引用,但由于历史原因 math.h不是对标准库模块的标题引用.编译程序时,默认情况下,链接器通常通常仅包含标准库.

string.h is a header reference to a module of the standard library, but due to historical reasons math.h is not a header reference to a module of the standard library. Only the standard library is typically included by default in the linker when compiling programs.

在某个时间点上,可以将 libm.so math.h 实现替换为针对内存,CPU性能等进行了更好优化的其他实现.不是单个 libm.so 默认"实现.但是,大多数系统至少提供了实现.该实现位于默认库位置,即 libm.so ,并将与 -lm 链接.

At one point in time, one might substitute libm.so math.h implementations with other implementations that were better optimized for memory, CPU performance, etc. Effectively there was not a single libm.so "default" implementation. However, most systems at least provided an implementation. That implementation is in the default library location as libm.so and would be linked in with -lm.

如果您拥有可以使用的更快(也许甚至会降低准确性)的库,则可以覆盖系统提供的 math.h libm.so 实现.

In the event that you had a faster (perhaps even at the expense of less accurate) library that you understood you could use, you had the ability to override the system-provided math.h libm.so implementation.

早期的CRAY系统(我没有做过)确实优化了一些数学实现,以不执行正确的完整"数学运算,但要了解要获得100%正确的答案,您将完成"由于计算中的有效位数,使用代码进行汇编操作通常并不重要.(根据我对华盛顿特区密码学博物馆展示的理解)

The early CRAY systems (I didn't work on one) did optimize a few math implementations to not do proper "full" math operations, with the understanding that to get a 100% correct answer, you would "finish" the assembly operations with code that often wasn't important due to the number of significant digits in the computation. (From my understanding of a Cryptology Museum display in Washsington D.C.)

多种实现的问题在于您现在可以选择,并且标准C库的结构并未为您提供实现的选择.

The problem with multiple implementations is that you now have a choice, and the standard C library is not structured to provide you with a choice of implementation.

这篇关于为什么math.h需要链接到makefile中而不是string.h中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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