# C programming - undefined reference to \`sqrt'

**URL:** <https://forums.suse.com/t/c-programming-undefined-reference-to-sqrt/35232>\
**Category:** General Discussion\
**Created:** [August 18, 2020, 5:04pm UTC](https://forums.suse.com/t/c-programming-undefined-reference-to-sqrt/35232 "2020-08-18T17:04:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Franz](https://avatars.discourse-cdn.com/v4/letter/f/c37758/32.png) [@Franz](https://forums.suse.com/u/Franz)\
**Post date:** [August 18, 2020, 5:04pm UTC](https://forums.suse.com/t/c-programming-undefined-reference-to-sqrt/35232/1 "2020-08-18T17:04:29Z")

</div>

I am about to start work on mathematical software with Leap 15.1using C. I ran into the following (elementary?!) problem: Compilation of the following C-program test.c  
#include \<stdio.h\>  
#include \<math.h\>

int main()  
{  
double x = 4.0;  
double y;

y = sqrt(x);  
printf("Wurzel von %lf: %lf  
", x, y);

return;  
}  
using command “gcc -ansi -pedantic test.c -o test.exe” results in the error message  
“/usr/lib64/gcc/x86\_64-suse-linux/7/…/…/…/…/x86\_64-suse-linux/bin/ld: /tmp/ccGo2pR5.o: in function `main': test.c:(.text+0x23): undefined reference to `sqrt’  
collect2: error: ld returned 1 exit status  
fjp@Tuxedo:~/ExponentialApproximation/EXPFJP/Programm\>”  
What can I do to correct this situation? The issue seems to the header file math.h.  
My Leap 15.1 installation was done with yast2  
Thanks in advance!

Franz Polster

---

<div class="post-metadata">

**Author:** ![malcolmlewis](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/malcolmlewis/32/11375_2.png) [@malcolmlewis](https://forums.suse.com/u/malcolmlewis)\
**Post date:** [August 18, 2020, 8:41pm UTC](https://forums.suse.com/t/c-programming-undefined-reference-to-sqrt/35232/2 "2020-08-18T20:41:06Z")

</div>

Hi and welcome to the Forum 🙂  
Unfortunately you have landed in the Enterprise forum rather than the openSUSE Community forum at [https://forums.opensuse.org](https://forums.opensuse.org)  
Since your here though, you have missed the linker flag (to math), compile with;

```auto
gcc -ansi -pedantic test.c -o test.exe -lm

```

---

<div class="post-metadata">

**Author:** ![Franz](https://avatars.discourse-cdn.com/v4/letter/f/c37758/32.png) [@Franz](https://forums.suse.com/u/Franz)\
**Post date:** [August 20, 2020, 8:10am UTC](https://forums.suse.com/t/c-programming-undefined-reference-to-sqrt/35232/3 "2020-08-20T08:10:56Z")

</div>

Thanks for the “-lm”, everything works fine now!  
My intention was to join openSUSE Community, obviously I chose the wrong button at page [de.opensuse.org/Portal:](http://de.opensuse.org/Portal:)…, IMHO a confusing, not really helpful page. I will try (i.e. register) again using the link given in your response, thanks for that too!  
Franz Polster
