c - 如何在Microsoft Visual Studio 2010中链接libm库

标签 c libm

请帮我看看如何在 Microsoft Visual Studio 2010 中链接 libm 数学库,

为了在 C 程序中使用一些三角函数?

最佳答案

只需要放置

#include <math.h>

在你的程序中。

在 VS2010 中的新空项目中,以下内容编译时不会出现错误或警告:

#include <stdio.h>
#include <math.h>

int main(){
  double a,b,c;
  char d;
  a = 0.0;
  b = cos(a);
  c = sqrt(b);
  printf("cos(%lf) = %lf, sqrt(cos(%lf)) = %lf\n", a, b, a, c);
  d = getchar();
  return 0;
}

这是 VS2010 编译输出:

1>------ Rebuild All started: Project: test3, Configuration: Debug Win32 ------
1>  source.c
1>  test3.vcxproj -> c:\users\andy\documents\visual studio 2010\Projects\test3\Debug\test3.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

如果我省略#include <math.h>我明白了:

1>------ Rebuild All started: Project: test3, Configuration: Debug Win32 ------
1>  source.c
1>c:\users\andy\documents\visual studio 2010\projects\test3\test3\source.c(9): warning C4013: 'cos' undefined; assuming extern returning int
1>c:\users\andy\documents\visual studio 2010\projects\test3\test3\source.c(10): warning C4013: 'sqrt' undefined; assuming extern returning int
1>  test3.vcxproj -> c:\users\andy\documents\visual studio 2010\Projects\test3\Debug\test3.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

无需对链接的 VS2010 库进行任何更改。

也没有红色下划线(智能感知错误)。

关于c - 如何在Microsoft Visual Studio 2010中链接libm库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25880793/

相关文章:

c - OS X 在 stdlib.h 中包含堆排序,这与排序库中的堆排序冲突

在 C 中使用 pow 时,CMake 能否检测到我是否需要链接到 libm?

ubuntu - 编译 ://lib/x86_64-linux-gnu/libm. so.6:添加符号时出错:缺少 DSO

math - 为 ARM 优化的 Libm?

c - 使用 glibc/libm 和 float32 的 atan2 的错误结果

c - 我需要编写一个程序,从文件中读取并将其更新为结构成员

c - 在 Ruby C 扩展中, "rb_..."C 函数是猴子修补版本还是原始版本?

c++ - libm.lib、libmmt.lib 和 libmmds.lib 之间有什么区别?

c - 将结构体数组作为参数传递给函数

c - 使用 appsink 提取样本信号