I could write a function prototype and main() and add #include <math.h>, but nothing seems to make that error about sqrt go away. What am I doing wrong? I am getting the same error on my Fedora31 laptop and our UbuntuMate 19.10 box at home
gcc -o root_error root_error.c
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /tmp/ccVjsV0O.o: in function `sqrt_real':
root_error.c:(.text+0x2a): undefined reference to `sqrt'
/usr/bin/ld: root_error.c:(.text+0x48): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
me wrote:If you aren't creating an executable, add -c to the compiler command line.
John Matthews wrote:Regarding the main error...
Campbell Ritchie wrote:Is complex a keyword? Gustedt suggested that the tgmath.h file would contain everything necessary to run that code.
campbell@xxxxx$ gcc root.c -lm
campbell@xxxxx$ ./a.out 123.45e67
The root of |1.2345e+69| is 3.51355e+34
Complex version of root = (3.51355e+34, 0i)
campbell@xxxxx$ ./a.out -123.45e67
The root of |-1.2345e+69| is 3.51355e+34
Negative number: Complex version of root = (0, 3.51355e+34i)
Campbell Ritchie wrote:I never knew you could do that. So I can get rid of the prototypes and move main() to the end? No sooner said that done.
If you have multiple functions in the same file, that does mean you have to declare them in a certain order, before they are used. If you declare prototypes for everything other than main(), you can have the functions in any order.
Tim Holloway wrote:As to the main(int argc, char **argv) versus main(int argc, char *argv), they are ultimately the same definition, just different notation.
John Matthews wrote:And argv[i] is how you normally access an array element.
Yes, I knew that bit. But the other info you provided is very interesting (as it always is). Thank you.
Tim Holloway wrote:. . . main(int argc, char **argv) versus main(int argc, char *argv), they are ultimately the same definition . . .