How to link to <math.h> library using CMake?

﹥>﹥吖頭↗ 提交于 2020-04-28 08:47:09

问题


I included <math.h> library in my source code. But I get compilation errors.

Error: 
**undefined reference to 'sqrt'
**undefined reference to 'atan'

How can I link to <math.h> in CMakeLists.txt?


回答1:


I found answer. Cmakelists.txt file is like it:

cmake_minimum_required(VERSION 3.6)
project(project_name)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")

set(SOURCE_FILES main.c)

add_executable(project_name ${SOURCE_FILES})

And you must add this command, for < math.h > or any standard library is similar.

target_link_libraries(project_name m)

That's all.



来源:https://stackoverflow.com/questions/40196373/how-to-link-to-math-h-library-using-cmake

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