如何链接到< math.h>库使用CMake? [英] How to link to <math.h> library using CMake?
本文介绍了如何链接到< math.h>库使用CMake?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在源代码中包含了< math.h>
库。但是我遇到编译错误。
I included <math.h>
library in my source code. But I get compilation errors.
Error:
**undefined reference to 'sqrt'
**undefined reference to 'atan'
如何链接到< math。 h>
在 CMakeLists.txt
中?
推荐答案
<我找到答案了。 Cmakelists.txt文件就是这样的:
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})
您必须添加此命令,以< math.h>或任何标准库都类似。
And you must add this command, for <math.h> or any standard library is similar.
target_link_libraries(project_name PRIVATE m)
仅此而已。
这篇关于如何链接到< math.h>库使用CMake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文