C 错误 - 在 Eclipse IDE 中未定义对 pow 的引用 - 可以在 'main' 函数中使用它,但不能在其他函数中使用。我正在使用 "-lm"编译器标志

标签 c eclipse compiler-errors

<分区>

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

const short int Z = 2;

const int parts = 1000;
const double epsilon = 1e-5;

typedef double (*func_n_l_r)(int, double);

double R_nl(int n, int l, double r) {
    return 2 * pow(Z, 1.5) * exp(-r * Z );
}

int main(void) {
    printf("%f",pow(3,2));
    return EXIT_SUCCESS;
}

在 main 中它编译并显示结果(如果我注释掉 R_nl 函数,当然),但它在 R_nl 函数中给我一个错误(与 exp 函数相同)。

使用 Eclipse Juno 进行 c/c++ 开发。

[编辑]:使用 -lm 标志。

[编辑]:使用带有参数的 gcc 编译器 -lm -E -P -v -dD "${plugin_state_location}/specs.c" 来自 Eclipse IDE - linux ubuntu 13.04。

[编辑]:编译器输出,我不知道为什么它看不到我在配置中给它的 -lm 参数....:|

08:13:52 **** Incremental Build of configuration Debug for project Helium ****
Info: Configuration "Debug" uses tool-chain "MinGW GCC" that is unsupported on this system, attempting to build anyway.
Info: Internal Builder is used for build
gcc -o Helium src/Helium.o 
src/Helium.o: In function `R_nl':
/home/shefuto/Dropbox/pt_sqala/Master 2/sem2/nagy/Helium/Debug/../src/Helium.c:28: undefined reference to `pow'

[编辑]:已解决:http://www.eclipse.org/forums/index.php?t=msg&th=68204/

显然有一个特殊的选项页面,您可以在其中指定链接器参数,其中“m”是您要添加的库,它会自动添加选项 -lm

最佳答案

您需要将 -lm 标志添加到编译(链接器)命令字符串。

gcc -lm ./main.c

见男人战俘

   #include <math.h>

   double pow(double x, double y);
   float powf(float x, float y);
   long double powl(long double x, long double y);

   Link with -lm. //<- Look here

关于C 错误 - 在 Eclipse IDE 中未定义对 pow 的引用 - 可以在 'main' 函数中使用它,但不能在其他函数中使用。我正在使用 "-lm"编译器标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16601550/

相关文章:

java - 用抽象编译错误,并且不覆盖抽象方法

c++ - 为什么这段代码不能编译?

c - C语言中的欧拉恒等式

c - getpass() 设置两个字符串相同?

eclipse - Eclipse语法着色文件

java - Eclipse 中这两种 JVM 设置有什么区别吗?

c++ - C2664错误,C++对我来说是陌生的

将字符串转换为链接列表

c - 简单的 C 枚举问题

javascript - 如何检查突出显示文本的 if else 条件?