2015-10-28 5 views
0

По какой-то причине, когда I #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; 
} 

Я использую G ++ 5.2 на Ubuntu 15.10

+1

Пожалуйста, напишите [MCVE] (https://stackoverflow.com/help/mcve) –

+0

Я не уверен, как повторить его с меньшим количеством кода, потому что я не знаю, что вызывает ошибку в коде. – chasep255

+2

@ chasep255 Затем попробуйте удалить материал и продолжать делать это до тех пор, пока ошибка не исчезнет. – Angew

ответ

1

Я нашел проблему. Я включил -fsingle-precision-constant в g ++. Это, я полагаю, ломает что-то с шаблонами внутри алгоритма.

+0

Вы можете отметить это как принятый ответ сейчас :) – Antzi

Смежные вопросы