包括算法会导致构建失败

时间:2015-10-28 12:03:09

标签: c++ algorithm

出于某种原因,当我#include算法时,我的构建失败并带有以下内容 错误。

make all 
Building file: ../Stacking.cpp
Invoking: GCC C++ Compiler
g++ -std=c++0x -fopenmp -O3 -march=native -ffast-math -funroll-loops -fsingle-precision-constant -g3 -Wall -c -fmessage-length=0  -pipe -fPIC -MMD -MP -MF"Stacking.d" -MT"Stacking.o" -o "Stacking.o" "../Stacking.cpp"
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc: In member function ‘void std::poisson_distribution<_IntType>::param_type::_M_initialize()’:
/usr/include/c++/5/bits/random.tcc:1408:55: error: no matching function for call to ‘max(float, const double&)’
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
                                                       ^
In file included from /usr/include/c++/5/algorithm:61:0,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1408:55: note:   deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘double’)
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
                                                       ^
In file included from /usr/include/c++/5/algorithm:61:0,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/5/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1408:55: note:   deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘double’)
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
                                                       ^
In file included from /usr/include/c++/5/bits/stl_algo.h:60:0,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/algorithmfwd.h:413:5: note: candidate: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp>);
     ^
/usr/include/c++/5/bits/algorithmfwd.h:413:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1408:55: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘float’
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
                                                       ^
In file included from /usr/include/c++/5/bits/stl_algo.h:60:0,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/algorithmfwd.h:418:5: note: candidate: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp>, _Compare);
     ^
/usr/include/c++/5/bits/algorithmfwd.h:418:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1408:55: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘float’
    _M_d = std::round(std::max(6.0, std::min(__m, __dx)));
                                                       ^
/usr/include/c++/5/bits/random.tcc: In member function ‘void std::binomial_distribution<_IntType>::param_type::_M_initialize()’:
/usr/include/c++/5/bits/random.tcc:1616:42: error: no matching function for call to ‘max(float, const double&)’
    _M_d1 = std::round(std::max(1.0, __d1x));
                                          ^
In file included from /usr/include/c++/5/algorithm:61:0,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1616:42: note:   deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘double’)
    _M_d1 = std::round(std::max(1.0, __d1x));
                                          ^
In file included from /usr/include/c++/5/algorithm:61:0,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/5/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1616:42: note:   deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘double’)
    _M_d1 = std::round(std::max(1.0, __d1x));
                                          ^
In file included from /usr/include/c++/5/bits/stl_algo.h:60:0,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/algorithmfwd.h:413:5: note: candidate: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp>);
     ^
/usr/include/c++/5/bits/algorithmfwd.h:413:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1616:42: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘float’
    _M_d1 = std::round(std::max(1.0, __d1x));
                                          ^
In file included from /usr/include/c++/5/bits/stl_algo.h:60:0,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/algorithmfwd.h:418:5: note: candidate: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp>, _Compare);
     ^
/usr/include/c++/5/bits/algorithmfwd.h:418:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1616:42: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘float’
    _M_d1 = std::round(std::max(1.0, __d1x));
                                          ^
/usr/include/c++/5/bits/random.tcc:1620:42: error: no matching function for call to ‘max(float, const double&)’
    _M_d2 = std::round(std::max(1.0, __d2x));
                                          ^
In file included from /usr/include/c++/5/algorithm:61:0,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1620:42: note:   deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘double’)
    _M_d2 = std::round(std::max(1.0, __d2x));
                                          ^
In file included from /usr/include/c++/5/algorithm:61:0,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/5/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1620:42: note:   deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘double’)
    _M_d2 = std::round(std::max(1.0, __d2x));
                                          ^
In file included from /usr/include/c++/5/bits/stl_algo.h:60:0,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/algorithmfwd.h:413:5: note: candidate: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp>);
     ^
/usr/include/c++/5/bits/algorithmfwd.h:413:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1620:42: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘float’
    _M_d2 = std::round(std::max(1.0, __d2x));
                                          ^
In file included from /usr/include/c++/5/bits/stl_algo.h:60:0,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/algorithmfwd.h:418:5: note: candidate: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp>, _Compare);
     ^
/usr/include/c++/5/bits/algorithmfwd.h:418:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/random:51:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from ../Stacking.cpp:1:
/usr/include/c++/5/bits/random.tcc:1620:42: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘float’
    _M_d2 = std::round(std::max(1.0, __d2x));
                                          ^
subdir.mk:21: recipe for target 'Stacking.o' failed
make: *** [Stacking.o] Error 1

如果我不包含算法,我的代码编译好并运行。此外,我试图将其包含在我的一些其他文件中,它工作正常。这是我的标题和cpp文件。我试图在图像中注册星星。

标题

#ifndef _STACKING_HPP_
#define _STACKING_HPP_

#include <vector>
#include "Image.hpp"

struct Star
{
    float x, y, magnitude;
};

std::vector<Star> registerImage(const cpimg::Image& img);

#endif

代码

#include <algorithm>
#include "Stacking.hpp"
#include <stack>


//using namespace cpimg;

typedef cpimg::Image::dim_t dim_t;
typedef cpimg::Image::Pixel Pixel;

static Star registerAndErase(cpimg::Image& img, dim_t row, dim_t col)
{
    struct Point
    {
        dim_t r, c;
        Point(dim_t row, dim_t col) :
            r(row), c(col) { }
    };

    std::stack<Point> to_visit;
    to_visit.push(Point(row, col));

    float row_integral = 0.0f;
    float col_integral = 0.0f;
    float total_lum = 0.0f;

    while(!to_visit.empty())
    {
        Point p = to_visit.top();
        to_visit.pop();

        float lum = img[p.r][p.c].red;
        total_lum += lum;

        row_integral += lum * p.r;
        col_integral += lum * p.c;

        img[p.r][p.c].red = 0.0f;

        if(p.r > 0 && img[p.r - 1][p.c].red)
            to_visit.push(Point(p.r - 1, p.c));

        if(p.r < img.height() - 1 && img[p.r + 1][p.c].red)
            to_visit.push(Point(p.r + 1, p.c));

        if(p.c > 0 && img[p.r][p.c - 1].red)
            to_visit.push(Point(p.r, p.c - 1));

        if(p.c < img.width() - 1 && img[p.r][p.c + 1].red)
            to_visit.push(Point(p.r, p.c + 1));
    }

    Star s;
    s.x = col_integral / total_lum;
    s.y = row_integral / total_lum;
    s.magnitude = total_lum;

    return s;
}


std::vector<Star> registerImage(const cpimg::Image& img)
{
    std::vector<Star> stars;

    cpimg::Image cpy = img.greyscale(cpimg::Image::Max).median_filter(1).gaussian_blur(1, 2);

    float p999 = cpy.percentile(cpimg::Image::Red, 0.999);

    #pragma omp parallel for
    for(dim_t i = 0; i < cpy.height(); i++)
        for(dim_t j = 0; j < cpy.width(); j++)
            if(cpy[i][j].red < p999)
                cpy[i][j] = Pixel(0.0f, 0.0f, 0.0f);

    for(dim_t i = 0; i < cpy.height(); i++)
    {
        for(dim_t j = 0; j < cpy.width(); j++)
        {
            cpy[i][j].green = 0.0f;
            if(cpy[i][j].red)
            {
                stars.push_back(registerAndErase(cpy, i, j));
            }
        }
    }

    /*
    std::sort(stars.begin(), stars.end(), [](const Star& a, const Star& b)
    {
        return a.magnitude < b.magnitude;
    });
    */

    for(Star s : stars)
    {
        dim_t r = s.y;
        dim_t c = s.x;
        cpy[r][c].green = 1.0f;
    }

    FILE* f = popen("display /dev/stdin", "w");
    cpy.write_ppm(f);
    pclose(f);

    return stars;
}

我在Ubuntu 15.10上使用G ++ 5.2

1 个答案:

答案 0 :(得分:2)

我发现了问题。我在g ++中启用了-fsingle-precision-constant。我想这是用算法中的模板打破了一些东西。