Build and run project that use math.h in Clion [duplicate]

人盡茶涼 提交于 2019-12-01 11:21:55

问题


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})

回答1:


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)


来源:https://stackoverflow.com/questions/39150697/build-and-run-project-that-use-math-h-in-clion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!