cmath函数生成编译器错误 [英] cmath functions generating compiler error

查看:270
本文介绍了cmath函数生成编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小程序,利用Fast Light工具包,并且由于某种原因,当试图访问cmath头中的函数时会产生编译器错误。

I've written a small program that utilizes the Fast Light Toolkit and for some reason a compiler error is generated when trying to access the functions in the cmath header.

如错误:: acos尚未声明。

Such as error ::acos has not been declared.

几乎每个函数试图在标题中使用。

This goes on for pretty much every function it tries to use in the header. What could I be missing?

我包含的头文件是

Simple_window.h
Graph.h

这两个都是FLTK的一部分。

both of which are part of the FLTK.

代码如下:

    #include "Simple_window.h"  // get access to our windows library
    #include "Graph.h"          // get access to graphics library facilities

    int main()
    {
        using namespace Graph_lib; // our graphics facilities are in Graph_lib

        Point tl(100,100);         // to become top left corner of window

        Simple_window win(tl,600,400,"Canvas"); // make a simple window

        Polygon poly; // make a shape (a polygon)

        poly.add(Point(300,200));     // add a point
        poly.add(Point(350,100));     // add another point
        poly.add(Point(400,200));     // add a third point

        poly.set_color(Color::red);   // adjust properties of poly

        win.attach(poly);             // connect poly to the window

        win.wait_for_button();        // give control to display engine
    }

编辑:编译器错误生成。这是在cmath标头内。

Here is example code of when the compiler error is generated. This is inside the cmath header.

namespace std
{
  // Forward declaration of a helper function.  This really should be
  // an `exported' forward declaration.
  template<typename _Tp> _Tp __cmath_power(_Tp, unsigned int);

  inline double
  abs(double __x)
  { return __builtin_fabs(__x); }

  inline float
  abs(float __x)
  { return __builtin_fabsf(__x); }

  inline long double
  abs(long double __x)
  { return __builtin_fabsl(__x); }

  using ::acos;  //ERROR HERE

  inline float
  acos(float __x)
  { return __builtin_acosf(__x); }

  inline long double
  acos(long double __x)
  { return __builtin_acosl(__x); }

  template<typename _Tp>
    inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
    acos(_Tp __x)
    {
      return __builtin_acos(__x);
    }

编辑:Code :: blocks将文件保存为C文件....

Code::blocks is saving files as C files....

推荐答案

当您包含标准C库的C ++版本(< cXXXX>)时,所有符号都在std命名空间。在C ++中,不需要链接到数学库(不需要-lm)

When you include the C++ version (<cXXXX>) of standard C libraries all the symbols are defined within the std namespace. In C++ you do not need to link against the math library (-lm is not required)

#include <cmath>
#include <iostream>

int main()
{
   std::cout << std::fabs( -10.5 ) << std::endl;
}

这篇关于cmath函数生成编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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