在Clion中构建并运行使用math.h的项目 [英] Build and run project that use math.h in Clion
问题描述
如何在Clion中添加诸如 -lm
(用于math.h)的标记来构建和运行c文件?
How do I add flags like -lm
(for math.h) in Clion to build and run a c file?
我基本上想使用 math.h $中的
pow()
函数c $ c>在我的代码中,然后在Clion中运行和调试相同的代码。
I basically want to use pow()
function from math.h
in my code and run and debug the same in Clion.
我是CMake的新手。
这是我的CMakeLists.txt:
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})
推荐答案
您需要将 target_link_libraries(YOUR_TARGET_NAME_HERE m)
添加到您的 CMakeLists.txt
文件中。
You need to add target_link_libraries(YOUR_TARGET_NAME_HERE m)
to your CMakeLists.txt
file.
(如果您尝试过此操作,或者不知道目标名称是什么,请添加您的 CMakeLists.txt
文件提交给您的问题)
(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)
编辑:您的目标名称为 Assign2
,因此在您的 CMakeLists.txt
的底部,您需要添加:
your target name is Assign2
, so at the bottom of your CMakeLists.txt
, you need to add:
target_link_libraries(Assign2 m)
这篇关于在Clion中构建并运行使用math.h的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!