Undefined reference to sqrt()
I include the <math.h> but the code still not recognising basic operations such as sqrt or pow. https://code.sololearn.com/cEBuyGQdCrHL/?ref=app
First of all, don't be frustrated and congratulation as you've just discovered a bug in SoloLearn! After a quick check I believe it's a linker problem of the C online compiler used by SoloLearn. You may report this behaviour to [email protected] and meanwhile you may try to run your code at other cloud compilers available like:- https://www.onlinegdb.com P/S: I've verified with link above and it works! 😉
Hi Zephyr Koo , It's been a long time! Been busy with work I guess? This is really intriguing case, because I could get the code to run (Yes in Code Playground) when I pass a literal value as argument for `sqrt` printf("sqrt(361) = %.0lf", sqrt(361)); // this works, strangely At first I thought the problem was with the format specifier "%d\n" at line 10, but nope, I was wrong. It still doesn't work although I changed it to "%d" only. Tried to change some numbers by adding decimal point, and occasional casting, but it didn't work either. s = s + 1.0 / (double)(i*i); // didn't help pi = sqrt(6.0 * s); // didn't help Looking forward for others' opinions : )
I also tried the code with no modifications on my machine, no issues. Ipang seems to have found a temporary fix for now. Another suggestion is to write your own version of the sqrt function. Sure it may not be as efficient as the library one but it will give you the experience of understanding how the function is built. 🙂
Chum4k3r Wow indeed thanks for informing! It's probably the weirdest bug I've seen in SoloLearn. 👍
Zephyr Koo it's pretty common with initial setups.
Guillermo Alonso Zephyr Koo Ace I found these on SO, seems it be a compiler issue (gcc if I understand it correctly). No experience with compiler command options so I'm leaving this to you guys 👍 [Referenced from the thread below] https://stackoverflow.com/questions/5248919/undefined-reference-to-sqrt-or-other-mathematical-functions [Marked as duplicate (forwarded to one above)] https://stackoverflow.com/questions/10409032/why-am-i-getting-undefined-reference-to-sqrt-error-even-though-i-include-math
Ipang Yup it has been awhile and feel grateful to be able to come back from time to time! You've got some good observation and I really wonder the strange behaviour as well. Nice catch! 😉
I was facing this issue in my code yesterday, but today it worked. Seems like the linker bug has been fixed
Good to have you back Zephyr Koo 👍
What i do wrong ?
Please rearrange int array:
Помогите с кодом автобуса
self parameter in python class