相关疑难解决方法(0)

为什么必须在C中链接数学库?

如果我包含<stdlib.h><stdio.h>在C程序中,我不必在编译时链接这些,但我必须链接到<math.h>,使用-lmgcc,例如:

gcc test.c -o test -lm
Run Code Online (Sandbox Code Playgroud)

这是什么原因?为什么我必须显式链接数学库而不是其他库?

c compilation math.h

241
推荐指数
7
解决办法
11万
查看次数

"未定义引用`pow'",即使是math.h和库链接-lm

我正在使用math.h-lm编译的选项.我尝试了所有:

gcc -o ssf ssf_tb.c ssf.c -lm
gcc -o ssf ssf_tb.c -lm ssf.c   
gcc -o -lm ssf -lm ssf_tb.c ssf.c
Run Code Online (Sandbox Code Playgroud)

但错误:

undefined reference to 'pow'  
Run Code Online (Sandbox Code Playgroud)

在所有情况下都会发生

c linux math gcc

10
推荐指数
1
解决办法
2万
查看次数

Unable to include cmath using GCC 5.5 on Solaris 10

I am trying to run the following test program on my Solaris 10 sparc machine using gcc 5.5.0

#include <iostream>
#include <cmath>

int main()
{
    std::cout << "exp2(4) = " << std::exp2(4) << '\n'
              << "exp2(0.5) = " << std::exp2(0.5) << '\n'
              << "exp2(-4) = " << std::exp2(-4) << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Here are the OS details,

~$ uname -a
SunOS sovms577 5.10 Generic_147147-26 sun4v sparc SUNW,SPARC-Enterprise-T5220
~$ cat /etc/release 
                   Oracle Solaris 10 1/13 s10s_u11wos_24a SPARC
  Copyright (c) 1983, …
Run Code Online (Sandbox Code Playgroud)

c++ gcc solaris solaris-10

5
推荐指数
1
解决办法
659
查看次数

pow()未定义

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

void main()
{
    int i, diff, sum = 0, num1 = 6, num2 = 2;

    for(i = 0; i <= 4; i++)
    {
        diff = num1 - num2;
        sum += pow(diff, i);
    }

    printf("%d", sum);
}
Run Code Online (Sandbox Code Playgroud)

每当我尝试执行此程序时,会弹出一条错误消息:

在函数中main:
未定义引用pow.

我在这里错过了什么?

c

3
推荐指数
2
解决办法
294
查看次数

标签 统计

c ×3

gcc ×2

c++ ×1

compilation ×1

linux ×1

math ×1

math.h ×1

solaris ×1

solaris-10 ×1