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/cpp_questions › undefined reference to `pow'
r/cpp_questions on Reddit: undefined reference to `pow'
April 17, 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

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

Find elsewhere
🌐
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.
🌐
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 19, 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 ...
🌐
OpenGenus
iq.opengenus.org › undefined-reference-to-pow-floorf-and-floor
[FIXED] Undefined reference to 'pow', 'floorf' and 'floor'
April 2, 2023 - In this article, we have presented 3 ways to fix the error "Undefined reference to 'pow', 'floorf' and 'floor'" while compiling C programs.
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 123684-undefined-reference-`pow.html
: undefined reference to `pow'
February 9, 2010 - Q1. Because of the default prototype presumed by the compiler for "pow()". It's a bad idea to not include the prototype. See the C89 standard for more information. Q2. Probably left over object files and linkage. Delete all the generated files (including ones in tmp) then you'll most likely get the error again.
🌐
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
🌐
YouTube
youtube.com › watch
Cannot use pow(), sqrt() in C | Undefined reference to pow ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
Gsu
hallertau.cs.gsu.edu › ~mweeks › csc3320 › undef_ref_sqrt.txt
Undefined reference to sqrt
Here's an example: [myacct123@gsuad.gsu.edu@snowball]$ gcc hmwk4_myacct123.c /tmp/cc9RiswK.o: In function `getDistance': hmwk4_jhill144.c:(.text+0x26d): undefined reference to `pow' hmwk4_jhill144.c:(.text+0x297): undefined reference to `pow' hmwk4_jhill144.c:(.text+0x2a1): undefined reference to `sqrt' collect2: error: ld returned 1 exit status [myacct123@gsuad.gsu.edu@snowball]$ gcc hmwk4_myacct123.c -lm Notice that the fix is not changing the C program, but changing the command to compile/link it.
🌐
7-Zip Documentation
documentation.help › C-Cpp-Reference › pow.html
pow - C/C++ Reference Documentation
The pow() function returns base raised to the expth power. There's a domain error if base is zero and exp is less than or equal to zero. There's also a domain error if base is negative and exp is not an integer.
🌐
Quora
quora.com › How-do-you-fix-undefined-reference-to-function-in-c-c-c-functions-compilation-development
How to fix 'undefined reference to 'function' in c (c, c ++, functions, compilation, development) - Quora
For functions provided by external libraries (math, pthreads, SDL, etc.), pass the appropriate -l options: e.g. -lm for libm (useful if using pow, sin in C linking with some compilers), -lpthread for pthreads, -lstdc++ rarely required if you use g++; linking C++ objects with gcc might need -lstdc++. For Windows/MSVC, add the .lib import library or ensure project references are set.
🌐
GitHub
github.com › hpcgarage › spatter › issues › 33
link error: undefined reference to `pow' · Issue #33 · hpcgarage/spatter
May 19, 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