Home » C programming

Error - undefined reference to 'pow' with C program in GCC Linux

Fixing undefined reference to 'pow' in Linux

This is a common error while compiling C program in GCC/G++ Linux. This error occurs when you are using pow function to calculate power of a number in your programs.

To fix this problem ensure following points:

  • Include header file math.h in your program.
  • Add –lm linker flag with compilation command.

1- Include Header file

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

2- Compile command

    gcc  main.c -o main -lm

To more explanation : Compiling C program with math.h library in Linux.

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions

We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.