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
🌐
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.

Discussions

c - Undefined reference to `pow' and `floor' - Stack Overflow
You can now see, functions pow, floor are linked to GLIBC_2.2.5. Parameters order is important too, unless your system is configured to use shared librares by default, my system is not, so when I issue: $ gcc -lm fib.o fib.o: In function `fibo': fib.c:(.text+0x57): undefined reference to `pow' ... More on stackoverflow.com
🌐 stackoverflow.com
c - Undefined reference to pow when compiled using gcc - Stack Overflow
/usr/bin/ld: /tmp/ccUkOL31.o: in function `main': a1B.c:(.text+0xf3): undefined reference to 'pow' collect2: error: ld returned 1 exit status · Although I read on StackOverflow that linking is required. But that's weird. Is there any way to avoid that extra step when we are compiling with gcc. More on stackoverflow.com
🌐 stackoverflow.com
link error: undefined reference to `pow'
Ubuntu 16.04.4 LTS gcc version 5.4.0 In build_omp_gnu: [100%] Linking C executable spatter /spatter.dir/src/json.c.o: In function json_parse_ex': json.c:(.text+0xe2a): undefined reference to pow' j... More on github.com
🌐 github.com
4
July 30, 2019
[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 30, 2015
🌐
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.
🌐
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 - To solve the "undefined reference to pow" error, follow these steps: Include the Math Header: Ensure your code includes the math header. #include <math.h> Link the Math Library: Use the -lm flag when compiling your code. Here are some examples for different compilers: GCC (GNU Compiler Collection): gcc -o myprogram myprogram.c -lmThis tells GCC to link the math library with your program.
🌐
Stack Overflow
stackoverflow.com › questions › 68359935 › undefined-reference-to-pow-when-compiled-using-gcc
c - Undefined reference to pow when compiled using gcc - Stack Overflow
I am using pow function in C and included the math.h library too The following is the error that I am getting : /usr/bin/ld: /tmp/ccUkOL31.o: in function `main': a1B.c:(.text+0xf3): undefined refe...
Find elsewhere
🌐
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),
🌐
GitHub
github.com › hpcgarage › spatter › issues › 33
link error: undefined reference to `pow' · Issue #33 · hpcgarage/spatter
July 30, 2019 - Ubuntu 16.04.4 LTS gcc version 5.4.0 In build_omp_gnu: [100%] Linking C executable spatter /spatter.dir/src/json.c.o: In function json_parse_ex': json.c:(.text+0xe2a): undefined reference to pow' json.c:(.text+0x1466): undefined referenc...
Author   john-wilkes
🌐
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 30, 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)

🌐
GitHub
github.com › anotheremily › bin2txt › issues › 1
make fail, undefined reference to `pow', math lib problem · Issue #1 · anotheremily/bin2txt
July 30, 2019 - 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...
Author   anarkia7115
🌐
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
July 22, 2022 - The undefined reference to pow error is invoked if we miss the <math.h> header file or the program is not compiled correctly. To avoid this error, make sure you have included the header file and it is recommended to compile the program using ...
🌐
GitHub
github.com › kevinlekiller › amdctl › issues › 13
Make fails - undefined reference to 'pow' · Issue #13 · kevinlekiller/amdctl
November 1, 2007 - $ make gcc -Wall -pedantic -Wextra -std=c99 -O2 -lm amdctl.c -o amdctl /usr/bin/ld: /tmp/ccAmmJxI.o: in function `northBridge': amdctl.c:(.text+0x10ce): undefined reference to `pow' collect...
Author   echaskaris
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 123684-undefined-reference-`pow.html
: undefined reference to `pow'
September 2, 2020 - Look up a C++ Reference and learn How To Ask Questions The Smart Way ... You provided constants for both the inputs to pow, so I'm betting the compiler made an optimization and replaced the call with the literal value, or inlined pow for you, since pow(10,2) will always be the same value, and you didn't define pow in any way. That seems to be the case with this thread: gcc and pow in a C program - JustLinux Forums, where they actually look at the assembly outputted by gcc to see what was going on.
🌐
Ubuntu Forums
ubuntuforums.org › showthread.php
undefined reference to 'pow'
June 12, 2019 - The meeting point for the Ubuntu community.
🌐
Nkaushik
nkaushik.com › linux › undefined-reference-to-pow-error-fix
Fix - Undefined reference to 'pow' error in Linux | N Kaushik
January 27, 2022 - The main reason of this issue is that the definition of the pow function is not found. If you are adding math.h to the program file, you are adding the declaration of the pow function. But it doesn’t adds the definition of pow. So, the compiler will not find the definition and it will throw ...
🌐
GitHub
gist.github.com › 842e1fb0a847054cc87d
gcc - C: Undefined reference to pow Eclipse · GitHub
November 27, 2013 - Right click on your project -> properties -> C/C++ Build -> Settings -> GCC Linker -> Libraries -> add "m" -> Apply -> build
🌐
OpenGenus
iq.opengenus.org › undefined-reference-to-pow-floorf-and-floor
[FIXED] Undefined reference to 'pow', 'floorf' and 'floor'
July 29, 2024 - In this article, we have presented 3 ways to fix the error "Undefined reference to 'pow', 'floorf' and 'floor'" while compiling C programs. Table of contents: Error · Fix 1: Include math.h · Fix 2: Add flag -lm · Fix 3: Use LD_PRELOAD · On compiling a C program, you may face any error as follows: Command: gcc code.c ·