对“sqrt”的未定义引用
我的程序的一部分是计算浮点数的sqrt
。 当我写 sqrt(1.0f);
时,我成功编译了程序,但是当我写 sqrt(-1.0f);
时 编译失败,未定义引用'sqrt'
- 我想在这种情况下将返回nan
值... 我使用 gcc 编译该程序。 当我用 Visual Studio 编译它时,它已成功编译,并带有 sqrt 的负参数。 问题如何解决 谢谢
Part of my program is to calculate sqrt
of float number.
When I write sqrt(1.0f);
I success to compile the program,but when I write sqrt(-1.0f);
the compilation fails with undefined reference to 'sqrt'
- I suppose that in this case the nan
value will be returned...
I compile the program uing gcc.
When I compile it with visual studio it is compiled successfuly with negative argument to sqrt.
How the problem could be solved
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在大多数基于 Unix 的系统上添加
-lm
标志,如下所示:编译使用:
然后链接使用:
或者,如果您不想分开两个编译步骤,只需编写:
You have to add the
-lm
flag on most Unix-based systems, as in:Compile using:
and then link using:
Or if you don't want to separate the two compilation steps, simply write:
使用
-lm
链接以链接数学库Link with
-lm
to link with the math library