CMAKE_CXX_FLAGS are flags for the C++ compiler. -l is a linker flag. To link to a library, use this:

target_link_libraries(alfa_1 m)

You might also want to replace -std=c11 with use of CMAKE_C_STANDARD and related variables (CMAKE_C_STANDARD_REQUIRED, CMAKE_C_EXTENSIONS), and possibly replace use of CMAKE_CXX_FLAGS with a call to target_compile_options().

Answer from Angew is no longer proud of SO on Stack Overflow
🌐
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 ...
Author   john-wilkes
🌐
CMake Discourse
discourse.cmake.org › usage
pow with variable throws error - Usage - CMake Discourse
April 22, 2020 - Hi, I’m new to C. When I try variable in pow function (for example pow(hightSq,2)) it returns "undefined reference to ‘pow’ ". I’ve read that it has to do something with UNIX compatibility and that you have to add argume…
People also ask

What Is an Undefined Reference in C Programming Language?
A reference remains undefined in C programming language when a reference to a relocatable object (function, class, variable, etc) does find its definition even after searching all the object files. Also, when you use a shared object to build a dynamic application but you leave an unresolved reference definition.
🌐
positioniseverything.net
positioniseverything.net › home › undefined reference to `pow’: fixing the error
Undefined Reference to `Pow’: Fixing the Error - Position Is ...
What Types of Data Does Pow() Return?
The pow() function will return the base value to the exponent. Both the base value and the power or exponent are in decimal values. This is because the pow() function accepts float, double, and int. It is important to note that function does not always work with integers.
🌐
positioniseverything.net
positioniseverything.net › home › undefined reference to `pow’: fixing the error
Undefined Reference to `Pow’: Fixing the Error - Position Is ...
🌐
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 - 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...
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 206607085-CLion-Enabling-math-h-for-C-projects
CLion - Enabling for C projects – IDEs Support (IntelliJ Platform) | JetBrains
Hello there ))Have a little question about math.h library.From what I know (a bit googling) math.h is not enabled by default, so a compiler raises an error: "undifined referece to pow"In order to ...
🌐
Position Is Everything
positioniseverything.net › home › undefined reference to `pow’: fixing the error
Undefined Reference to `Pow’: Fixing the Error - Position Is Everything
November 11, 2025 - As pointed out, you will trigger the undefined reference to ‘sqrt’ if your program does not import the math.h header file while you use the pow() function in C. Pow in C is part of the math.h header file.
Find elsewhere
🌐
w3tutorials
w3tutorials.net › blog › how-to-link-to-the-c-math-library-with-cmake
How to Link the C Math Library with CMake: Fix 'Undefined Reference to pow' Error (Step-by-Step Example) — w3tutorials.net
This error occurs because the C math library (libm) is not linked by default—you must explicitly tell the linker to include it. In this blog, we’ll demystify this error, walk through a step-by-step example to fix it using CMake, and explain ...
🌐
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 - Enter this header into your C program ... that will compile the file: ... The undefined reference to pow error is invoked if we miss the <math.h> header file or the program is not compiled correctly....
🌐
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.

🌐
YouTube
youtube.com › watch
C Cmake setup - undefined reference to pow() (despite -lm) (3 Solutions!!) - YouTube
C Cmake setup - undefined reference to pow() (despite -lm)Helpful? Please use the *Thanks* button above! Or, thank me via Patreon: https://www.patreon.com/ro...
Published   July 30, 2025
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 79669-undefined-reference-pow-sqrt-even-though-math-h-header-there.html
"Undefined Reference" to pow and sqrt even though math.h header is there
Compiling this code tells me that there is no reference to pow() or sqrt(). The book didn't tell me under which header these functions are located but I assume they are under math.h.
🌐
GitHub
github.com › psi4 › psi4 › issues › 853
Build failure (current rev. f03a896): undefined reference to `pow', etc · Issue #853 · psi4/psi4
We try to nail it down in CMake, but sometimes it finds and uses a wrong version installed alongside another dependency.
🌐
Commonvisionblox
forum.commonvisionblox.com › programming questions › c-style api
An error occurs when building the GEVServer tutorial in C++ with CMake - C-style API - Common Vision Blox User Forum
August 30, 2021 - After running CMake on the GEVServer tutorial on the Raspberry Pi 4 with a 64bit ARM OS, the following error comes up when running the make command. [100%] Linking CXX executable QmlGevServer /usr/bin/ld: /opt/cvb/lib/libCVGevServer.so: undefined reference to `std::__cxx11::basic_stringstream , std::allocator ::basic_stringstream()@GLIBCXX_3.4.26' /usr/bin/ld: /opt/cvb/lib/libCVGevServer.so: undefined reference to `pow@GLIBC_2.29' /usr/bin/ld: /opt/cvb/lib/lib...
🌐
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
If your problem is with executing commands manually, then don't. Use make or cmake. Typing make is always 1 step. ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 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?