-2

I'm New to CLion. I have created a project which name is test12 and which file name is avs.c.

I'm Getting an Error of type Undefined reference 'sqrt'

CMakeListsta.txt is :

cmake_minimum_required(VERSION 3.13)
project (test12 C)
set(CMAKE_C_STANDARD 99)
add_executable(test12 avs.c) 

What changes should I do to make CMAKELISTS use math.h header in CLion?

karthik oggu
  • 35
  • 11
  • I edited the question so as to have a good format but it was hard to understand the question by itself. Please make sure to edit the question and make it clear enough – M.K Mar 18 '19 at 11:19
  • I'm getting error error undefined reference 'sqrt' when i use math.h header. How to make this work(math.h) in Clion? – karthik oggu Mar 18 '19 at 11:25
  • Please provide avs.c file showing your code. This does not sound like a cmake issue. – Gardener Mar 18 '19 at 11:36
  • #include #include void main() { int a=25,b; b=sqrt(a); printf("%d",b);} – karthik oggu Mar 18 '19 at 11:42

1 Answers1

2

It looks like math.his not enabled in CLion, so you need to enable it! Source here.

  1. add #include <math.h>
  2. add target_link_libraries( m) in CMakeLists.txt

The second command allows you to link with libm for the math functions.

Adding this to your makefile! (Check the source I gave you!!)

target_link_libraries(log m)
M.K
  • 1,464
  • 2
  • 24
  • 46