Why do you have to link the math library in C?

后端 未结 11 1213
难免孤独
难免孤独 2020-11-22 01:04

If I include or in a C program I don\'t have to link these when compiling but I do have to link to

11条回答
  •  没有蜡笔的小新
    2020-11-22 01:49

    I think it's kind of arbitrary. You have to draw a line somewhere (which libraries are default and which need to be specified).

    It gives you the opportunity to replace it with a different one that has the same functions, but I don't think it's very common to do so.

    EDIT: (from my own comments): I think gcc does this to maintain backwards compatibility with the original cc. My guess for why cc does this is because of build time -- cc was written for machines with far less power than we have now. A lot of programs have no floating-point math and they probably took every library that wasn't commonly used out of the default. I'm guessing that the build time of the UNIX OS and the tools that go along with it were the driving force.

提交回复
热议问题