ç建设得到了罪的值时,误差() [英] C Build error when getting the value of sin()

查看:76
本文介绍了ç建设得到了罪的值时,误差()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习C作为一个辅助项目。我OpenSuse当中下工作,使用海合会作为工具集编译最新的NetBeans。
其中的第一方案,我做的是:

I have recently started learning C as a side project. I am working under OpenSuse with the latest NetBeans using the GCC as toolset for compiling. One of the very first programs that I made was this:

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

/*
 * 
 */
int main(int argc, char** argv) {    
    double rad = 1;
    double result = 0;
    result = sin(rad);
    return (EXIT_SUCCESS);
}

这是应该没有问题的工作简单,想都不用想的例子。在编译的时候退出code 2(第18行,未定义的引用错误罪):不过,我得到生成错误。
有趣的是,如果我删除罪(RAD)的值的分配导致或用硬codeD值替换弧度,程序编译就好了。
我在做什么错在这里?

This is a simple, no-brainer example that should have worked without a problem. However, I get a Build Error: Exit code 2(error in line 18, undefined reference to sin) when trying to compile. Interestingly enough, if I remove the assignment of the value of sin(rad) to result OR replace rad with a hard coded value, the program compiles just fine. What am I doing wrong here?

推荐答案

在C,你需要链接到数学库:

In C, you need to link to the math library:

这添加到命令行选项:

-lm

这篇关于ç建设得到了罪的值时,误差()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆