1

How do I add flags like -lm(for math.h) in Clion to build and run a c file?

I basically want to use pow() function from math.h in my code and run and debug the same in Clion.

I'm new to CMake.
This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(Assign2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.c)
add_executable(Assign2 ${SOURCE_FILES})
Jithin Pavithran
  • 1,250
  • 2
  • 16
  • 41

1 Answers1

4

You need to add target_link_libraries(YOUR_TARGET_NAME_HERE m) to your CMakeLists.txt file.

(If you've tried that, or don't know what's the name of your target, please add the contents of your CMakeLists.txt file to your question)


Edit: your target name is Assign2, so at the bottom of your CMakeLists.txt, you need to add:

target_link_libraries(Assign2 m)
melpomene
  • 84,125
  • 8
  • 85
  • 148
NiñoScript
  • 4,523
  • 2
  • 27
  • 33