You need to link with the math library:

gcc -o sphere sphere.c -lm

The error you are seeing: error: ld returned 1 exit status is from the linker ld (part of gcc that combines the object files) because it is unable to find where the function pow is defined.

Including math.h brings in the declaration of the various functions and not their definition. The def is present in the math library libm.a. You need to link your program with this library so that the calls to functions like pow() are resolved.

Answer from codaddict on Stack Overflow
Discussions

[C Programming] Undefined reference to pow and sqrt

you have to call gcc with -lm: https://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c

More on reddit.com
🌐 r/learnprogramming
5
3
November 24, 2015
"Undefined reference to pow" error after including <math.h> and the GCC option -lm
Im not even sure why that is the case, but I think you have to link the library as last argument. Try gcc -o output hexConverter.c -lm More on reddit.com
🌐 r/C_Programming
9
2
December 16, 2021
ide - c language math library error when compiling (pow) - Stack Overflow
I can compile the program in my computer with visual 08 and codeblocks, but then I try to use my school IDE I get some errors. /tmp/ccD2ZV6Q.o: In function `main': knit2.c:(.text+0x8d): undefined reference to `pow' knit2.c:(.text+0xce): undefined reference to `pow' knit2.c:(.text+0x11b): undefined ... More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2020
make fail, undefined reference to `pow', math lib problem
Make error message: make gcc -c driver.c gcc -c convert.c gcc -lm -o bin2txt driver.o convert.o convert.o: In function `bin2txt': convert.c:(.text+0x70): **undefined reference to `pow'** co More on github.com
🌐 github.com
1
December 17, 2017
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 181675-issue-math-functions.html
issue with math functions
February 28, 2025 - It could have been the missing -lm that caused it not to work with variables for you (the compiler probably replaced pow(constant, constant) with a constant value without a call to pow())
🌐
LinuxQuestions.org
linuxquestions.org › questions › programming-9 › c-program-error-undefined-reference-to-pow-4175698172
C Program error : undefined reference to pow
July 22, 2021 - I typed a C program from the Internet that calculates Compound Interest. One of the lines in the program reads CIFuture = PAmount*(pow((1+ROI/100),
🌐
Reddit
reddit.com › r/learnprogramming › [c programming] undefined reference to pow and sqrt
r/learnprogramming on Reddit: [C Programming] Undefined reference to pow and sqrt
November 24, 2015 -

I'm trying to do my homework which is to make a program that calculates a hypotenuse, given two cathetus entered by the user. This is the code:

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

int main(void) {

    float primeiroCateto;
    float segundoCateto;
    float hipotenusa;

    setlocale(LC_ALL, "Portuguese");

    printf("Digite o valor do primeiro cateto:\n");
    scanf("%f", &primeiroCateto);
    printf("Digite o valor do segundo cateto:\n");
    scanf("%f", &segundoCateto);

    hipotenusa = sqrt(pow(primeiroCateto, 2) + pow(segundoCateto, 2));

    printf("A hipotenusa é igual a:\n%.2f", hipotenusa);
    return 0;
}

The problem is that when i try to copile the code using:

gcc -Wall -Wextra -o Atividade2_exercício5 Atividade2_exercício5.c

This error shows up:

/tmp/ccFsAgvS.o: In function `main':
Atividade2_exercício5.c:(.text+0x82): undefined reference to `pow'
Atividade2_exercício5.c:(.text+0x9d): undefined reference to `pow' 
Atividade2_exercício5.c:(.text+0xa7): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status

So what to do now? (i'm using vccode by the way)

🌐
IncludeHelp
includehelp.com › c-programming-questions › error-undefined-reference-to-pow-in-linux.aspx
Error - undefined reference to 'pow' with C program in GCC Linux
C - Call by Reference Vs. Call by Value ... C Vs. Embedded C ... C - Copy Two Bytes Int. to Byte Buffer ... 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.
🌐
Ubuntu Forums
ubuntuforums.org › showthread.php
undefined reference to 'pow'
April 29, 2008 - The meeting point for the Ubuntu community
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › "undefined reference to pow" error after including and the gcc option -lm
r/C_Programming on Reddit: "Undefined reference to pow" error after including <math.h> and the GCC option -lm
December 16, 2021 -

Hey y'all, as the title says, I'm a wee bit stuck trying to use the math.h library function "pow". Here's my code -

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

int main(int argc, char *argv[]) {

//OMITTED CODE

size_t i;
double j;
int k;
for(i = argLen - 1, k = 0; k < argLen; i--, k++) {
	j = pow(16, i);
	deciVals[k] = deciVals[k] * j;
}

//OMITTED CODE	

return 0;

}

Despite having math.h included, and using the -lm option for the GCC, I'm still getting this error -

>gcc -lm -o output hexConverter.c
/usr/bin/ld: /tmp/ccghjuxO.o: in function `main':
hexConverter.c:(.text+0x237): undefined reference to `pow'
collect2: error: ld returned 1 exit status

Any help would be appreciated, thanks guys.

🌐
Code::Blocks
forums.codeblocks.org › index.php
No math functions after upgrade to 20.03
September 2, 2020 - No math functions after upgrade to 20.03
🌐
Abundantcode
abundantcode.com › abundant code › undefined reference to `pow’ when compiling c program
Undefined reference to `pow' when compiling C program
July 18, 2020 - When trying to make a simple program in C and compiling it , there are times when you might get an error that you are missing the pow function when you have used them inspite of including the math.h header file.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-solve-undefined-reference-to-pow-in-c-language
How to solve undefined reference to `pow' in C language? - GeeksforGeeks
July 23, 2025 - The math library (libm) contains ... others. If you do not explicitly link this library during the compilation, the linker will not be able to find the definition of pow, resulting in an "undefined reference" error...
🌐
CodeGenes
codegenes.net › blog › using-pow-function-throws-undefined-reference-error-in-c
Undefined Reference to pow() in C: Why Using Variables (Even Doubles) Causes Errors & How to Fix It — codegenes.net
The "undefined reference to pow()" error is a linker error caused by missing the math library (libm). Variables (even doubles) trigger it because the compiler can’t optimize away the pow() call, requiring the real implementation from libm.
🌐
Code::Blocks
forums.codeblocks.org › index.php
Why windows don't show this error but i get this?
June 28, 2020 - Why windows don't show this error but i get this?
🌐
Stack Overflow
stackoverflow.com › questions › 61981449 › c-language-math-library-error-when-compiling-pow
ide - c language math library error when compiling (pow) - Stack Overflow
May 24, 2020 - I can compile the program in my computer with visual 08 and codeblocks, but then I try to use my school IDE I get some errors. /tmp/ccD2ZV6Q.o: In function `main': knit2.c:(.text+0x8d): undefined reference to `pow' knit2.c:(.text+0xce): undefined reference to `pow' knit2.c:(.text+0x11b): undefined reference to `pow' collect2: error: ld returned 1 exit status
🌐
Its Linux FOSS
itslinuxfoss.com › home › how to fix the “undefined reference to ‘pow’” error
How to fix the “undefined reference to ‘pow’” error – Its Linux FOSS
May 17, 2011 - The error “undefined reference to 'pow'” can occur due to the absence of the header file or due to incorrect compilation.
🌐
GitHub
github.com › anotheremily › bin2txt › issues › 1
make fail, undefined reference to `pow', math lib problem · Issue #1 · anotheremily/bin2txt
December 17, 2017 - Make error message: make gcc -c driver.c gcc -c convert.c gcc -lm -o bin2txt driver.o convert.o convert.o: In function `bin2txt': convert.c:(.text+0x70): **undefined reference to `pow'** collect2: error: ld returned 1 exit status makefil...
Author   anarkia7115