A compilation error occurs when a variable is included in the sqrt() argument.undefined reference. What should I do?

Asked 2 years ago, Updated 2 years ago, 77 views

As in the comment out statement, there is no problem if you directly substitute a number, but if you insert a variable, you will get a compilation error.
What should I do?

running environment:
Ubuntu
gcc 9.3.0

compilation results:

$gccsqrtyou.c 
/usr/bin/ld: /tmp/cc0MDw2q.o:in function `main':
sqrtyou.c: (.text+0x23): undefined reference to `sqrt'
collect2:error:ld returned1 exit status

source code:

sqrtyou.c

#include<stdio.h>
# include <math.h>

int main()
{
    double first = 2.0;
    double second;

    second = sqrt(first);
  // second = sqrt(2.0);

    printf("%f\n", second);
}

c gcc

2022-09-30 19:41

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.