图书馆不兼容? - C ++

时间:2013-02-05 20:17:48

标签: c++ function shared-libraries static-libraries

我试图解决Project Euler的第56个问题,并且在使用Big Integer Library时遇到了一些麻烦。这是代码:

#include <iostream>
#include "BigInteger.hh"
#include <cmath>
using namespace std;

int digitSum(BigInteger x){
int num[(int)floor(log10(x))+2];
int n = 0;
BigInteger sum = 0;

while (x != 0){
    sum += x - floor(x/10) * 10;
    x = floor(x/10);
    n++;
}

return sum.toInt();
}


int main(int argc, const char * argv[])
{

int max = 0;

for (int i = 1; i <= 100; i++){
    for (int j = 1; j <= 100; j++){
        cout << "i = %i, j = %i ",i,j;
        if (digitSum(pow(i,j)) < max)
            max = digitSum(pow(i,j));

    }

    }

cout << digitSum(pow(2,63));


return 0;
}

问题在于,当我尝试构建时,编译器使用log10floorpow函数在行上给出错误,说明它们已被使用但未定义。当我对#include "BigInteger.hh"行进行评论时,一切都很顺利,但这一次,当然,我无法使用Big Integer库。

为什么会出现这样的问题?怎么解决?

1 个答案:

答案 0 :(得分:0)

是编译器还是链接器问题?如果是后者,请尝试将-lm添加到命令行以链接数学库。假设GNU gcc在这里。