C programming - undefined reference to `sqrt'

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

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

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

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:…, 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