0

I was working with pow() function in c using vscode. And I want to use a variable in exponent parameter of power function i.e. pow (2, i). But i was getting error so, I used gcc programName.c -lm during compilation in terminal. Is there any way by which I can use normal compilation command like gcc programName.c and get output of program with same problem.

n = 10;
h = 0;
while (n > pow(2, h))
   h++;
printf("\n%d\n", h);

error: /tmp/ccptU1ZR.o: In function main': BinaryTree.c:(.text+0xd9): undefined reference topow' collect2: error: ld returned 1 exit status The terminal process terminated with exit code: 1

expected output : 4

1 Answers1

0

The -lm option is not a different type of compilation, rather it is telling the compiler (actually the linker) where to find the meaning or definition of the pow() function. So use -lm with no worries, all it says is that there are math functions in the code otherwise gcc will not bother looking on its own.

MotKohn
  • 3,485
  • 1
  • 24
  • 41