0

During compilation I have this error message.

$ clang greedy.c /tmp/greedy-e7d5e2.o: In function main': greedy.c:(.text+0x5c): undefined reference toround' clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have included math.h library. I have tried round(), roundf(), float round(float a), float roundf(float a). Same error message for all. Below is piece of my code converting due into cents and rounding.

 // Get due
float due;
printf("Amount owed : ");
scanf("%f", &due);
// Convert into cents
int cents;
float a;
a=due*100;
cents = roundf(a);`

`

6
  • Did you use make? Or did you manually type clang [flags]? If it is the latter you must link the math.h library with the -lm flag. – kluvin Oct 2 '16 at 10:27
  • okay I did not use make and I did not include the flag. Thank you I will try that :) – Pavan Oct 2 '16 at 11:00
  • It worked. Thanks a lot. :) :) – Pavan Oct 2 '16 at 11:02
  • Good! I recommend using make though, it has the benefit of providing clang all the flags that is required, and the flags that just are good to have. – kluvin Oct 2 '16 at 11:26
  • Glad this got solved. @M. Kleiven , can you add your comments as an answer so that Dippa7 can accept the answer and remove this from the unanswered question pool please? – Cliff B Oct 2 '16 at 21:17
1

Did you use make? Or did you manually type clang [flags]? If it is the latter you must link the math.h library with the -lm flag.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .