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().
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().
add the link of library in the cmakeList
add_library(math STATIC path/to/file.cpp)
add_executable(cmake_hello main.cpp)
target_link_libraries(cmake_hello math)
and in the class cpp
#include "path/to/file.hpp"
for mode detaills see this link
gcc - Undefined reference to pow( ) in C, despite including math.h - Stack Overflow
c - Undefined reference to `pow' and `floor' - Stack Overflow
link error: undefined reference to `pow'
undefined reference to `pow'
You need to compile with the link flag -lm, like this:
gcc fib.c -lm -o fibo
This will tell gcc to link your code against the math lib. Just be sure to put the flag after the objects you want to link.
Add -lm to your link options, since pow() and floor() are part of the math library:
gcc fib.c -o fibo -lm
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
Hello Guy,
I'm trying to implement Mosquitto via CLion and I'm getting this error (you could check the attached image).
PS. : I already included the header and I also added the directory of Mosquitto folder to the environment variables : C:\Program Files\mosquitto\devel...
Could you please take a look and help me out to solve this error?
Thanks in advanced
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.