0
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
7 odpowiedzi
+ 10
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 info@sololearn.com 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! 😉
+ 4
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 : )
+ 4
Chum4k3r Wow indeed thanks for informing! It's probably the weirdest bug I've seen in SoloLearn. 👍
+ 3
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
+ 3
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! 😉
+ 3
I was facing this issue in my code yesterday, but today it worked. Seems like the linker bug has been fixed
+ 2
Good to have you back Zephyr Koo 👍