c - pow() 函数不适用于 CLion
问题描述
所以我对这一切都很陌生,但是使用了 YouTube 教程,但由于某种原因,我的 pow 函数不起作用。例如:
printf ("%d", pow(4, 3));
它应该是 %d,因为我得到了双倍的权利吗?我尝试了 %d,但没有奏效。
这是我得到的错误:
error: use of undeclared identifier 'pow'
帮助一个新手,干杯。
解决方案
我意识到这是一个老问题,但答案实际上并不能解决问题,所以为了后代,这就是答案。
使用 Clion,您需要先添加#include <math.h>
到您的代码中,例如
#include <stdio.h>
#include <math.h>
int main() {
double a, b;
a = 2.0;
b = 4.0;
printf("2.0^4.0 = %f", pow(a, b));
return 0;
}
第二件事是您需要在 CMakeLists.txt 中添加 target_link_libraries(<target_name> m) 例如
cmake_minimum_required(VERSION 3.20)
project(example C)
set(CMAKE_C_STANDARD 99)
add_executable(example main.c)
target_link_libraries(example m)
推荐阅读
- python - 在 Python 中写入 XML 文件时出现错误 AttributeError: 'str' object has no attribute 'dom'
- java - 如何在给定代码中镜像选项卡?
- azure-devops - 在 Windows Server 2019 自托管代理上找不到 azure cli 扩展
- windows - Powershell 过滤来自 Get-WinEvent 的输出数据
- python - 将 cv.imread() 数据发送到 Keras 模型
- r - 在不使用 scale_x_continuous 的情况下更改刻度线标签
- reactjs - 如何设置路由以便在未经身份验证的情况下重定向到登录?
- javascript - 在 html 和 javascript 中创建表,但无法在日期列中使用 Datepicker
- random - 名称“randrange”未定义错误,密码生成器
- firebase - 使用时间戳使firestore文档“无效”的最简单方法