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

pow() function does not compile if either parameter not constant
Solved: The pow() function does not compile if either the parameters are not constants as shown in the following example #include double X = 10.0; More on community.infineon.com
🌐 community.infineon.com
May 21, 2019
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
May 21, 2019
c - Undefined reference to pow when compiled using gcc - Stack Overflow
Stack Overflow chat opening up to all users in January; Stack Exchange chat... ... 1 Why am I getting “undefined reference to sqrt” error even though I include math.h header? More on stackoverflow.com
🌐 stackoverflow.com
undefined reference to `pow'
Link with the math library. -lm More on reddit.com
🌐 r/cpp_questions
7
0
April 19, 2022
🌐
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.

🌐
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),
🌐
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.
Find elsewhere
🌐
Infineon Developer Community
community.infineon.com › home › forums › software › psoc creator & designer software › pow() function does not compile if either paramet...
Solved: pow() function does not compile if either paramet... - Infineon Developer Community
May 21, 2019 - Jump to solution · The pow() function does not compile if either the parameters are not constants as shown in the following example · #include <math.h> double X = 10.0; double Y = 5.0; void Test() { double Z; Z = pow(10.0, 5.0); // compiles correctly · Z= pow(X, 5.0); // generates error message 'Undefined reference to pow' Z= pow(10.0, Y); generates error message 'Undefined reference to pow' Z = pow(X, Y); // Generates error message 'Undefined reference to pow' } Is this intentional to limit code size?
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › undefined-reference-to-pow › td-p › 518052
Undefined Reference to pow() - STMicroelectronics Community
May 17, 2011 - I try to calculate some values using the STM32F103VET6 under a Linux development environment using the toolchain version arm-2008q1 and I cannot use the function pow().
🌐
GitHub
github.com › hpcgarage › spatter › issues › 33
link error: undefined reference to `pow' · Issue #33 · hpcgarage/spatter
May 21, 2019 - [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 reference to `pow' collect2: error: ld returned 1 exit status CMakeFiles/spatter.dir/build.make:233: recipe for target 'spatter' failed ·
Author   john-wilkes
🌐
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 reference to 'pow' collect2: error: ld returned 1 exit status
🌐
Reddit
reddit.com › r/cpp_questions › undefined reference to `pow'
r/cpp_questions on Reddit: undefined reference to `pow'
April 19, 2022 -

Hello! I have a very strange problem.

code:

#include <stdio.h>
#include <math.h>
int main() {
long long a = 1, b = 2;

double ans = pow(1, 2);

printf("%f", ans);
return 0;
}

--------------------------------------

return:

1.000000

============================================

code:

#include <stdio.h>
#include <math.h>
int main() {
long long a = 1, b = 2;

double ans = pow(a, b);

printf("%f", ans);
return 0;
}

--------------------------------------

return:
/usr/bin/ld: CMakeFiles/untitled.dir/main.c.o: in function \main':`

/home/tarminik/CLionProjects/untitled/main.c:7: undefined reference to \pow'`

collect2: error: ld returned 1 exit status

🌐
Gentoo Forums
forums.gentoo.org › viewtopic-p-8696606.html
Gentoo Forums :: View topic - undefined reference to 'pow'
April 2, 2022 - FAQ | Search | Memberlist | Usergroups | Statistics | Profile | Log in to check your private messages | Log in | Register · Links: forums.gentoo.org | www.gentoo.org | bugs.gentoo.org | wiki.gentoo.org | forum-mods@gentoo.org
🌐
OpenGenus
iq.opengenus.org › undefined-reference-to-pow-floorf-and-floor
[FIXED] Undefined reference to 'pow', 'floorf' and 'floor'
April 2, 2023 - The math library is named as libm.so and is usually, located in /lib or /usr/lib in UNIX system like Ubuntu. Go to these locations and try to locate libm.so.
🌐
Post.Byes
post.bytes.com › home › forum › topic
Undefined reference to pow - Post.Byes
September 21, 2007 - Re: Undefined reference to pow Yep. 'GCC -lm source.c' fixed it! Thanks again.
🌐
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 error “undefined reference to 'pow'” can occur due to the absence of the header file or due to incorrect compilation.
🌐
GitHub
github.com › facebookresearch › habitat-sim › issues › 1810
undefined reference to "pow@GLIBC_2.29" & "log@GLIBC_2.29" · Issue #1810 · facebookresearch/habitat-sim
April 20, 2022 - It is strange that my glibc version is 2.28, while the error is " undefined reference to `xxx@GLIBC_2.29'".
Author   YHWmz
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 181675-issue-math-functions.html
issue with math functions
May 22, 2023 - You most probably need to link against the math library - libm. For GCC you need the '-lm' compile option. The GCC compiler will optimize / inline some simple functions to improve performance rather than calling the library function, and pow(x,y) is one of them.
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
[SOLVED] Issues with Include in C / Programming & Scripting / Arch Linux Forums
My crystal ball says you're not linking in the necessary libraries, which would result in a message like "undefined reference to `pow' " (or whatever function you're trying to use). The functions declared in <stdio.h> are in libc.a, which is linked in by default; most of what's in <math.h> is in libm.a, which is not.