Timeline for Why do you have to link the math library in C?
Current License: CC BY-SA 2.5
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 16, 2020 at 11:05 | comment | added | clockw0rk | there IS a guarantee that this happens as long as you're not using some underdog distribution from late 2005 | |
| Jun 22, 2018 at 1:30 | comment | added | Donghua Liu | @BastienLéonard I use gcc of version 7.2, which the -lm is totally optional. Any ideas | |
| Mar 5, 2015 at 10:51 | comment | added | Bastien Léonard | @RockyInde: look at my answer, I think I actually meant “before the standard math library”. But I think there are compiler options to not link the standard C library, which would allow you to pass yours. | |
| Mar 5, 2015 at 9:17 | comment | added | Rocky Inde | @Bastien Good find. And coming to your point, what do you mean by "before the standard library" ? I thought, the standard library is linked in by default and is not required to be linked via command line options. So, the standard library will be the first go-to for the linker and one cannot place their own implementation "before the standard library". | |
| Aug 1, 2010 at 20:07 | comment | added | R.. GitHub STOP HELPING ICE | Indeed, making your own function (non-static) named sqrt results in a program with undefined behavior. | |
| Jun 23, 2009 at 20:45 | comment | added | ephemient | I don't think there's a guarantee that that'll happen; you might end up with a symbol conflict instead. It would probably depend on the linker and the layout of library. I still find that reason to be weak; if you're making a custom sqrt function, you really shouldn't give it the same name as the standard sqrt function, even if it does the same thing... | |
| Jun 23, 2009 at 19:45 | history | answered | Bastien Léonard | CC BY-SA 2.5 |