Menu

#17 compile failure with newer gcc

v1.0_(example)
closed
None
5
2020-08-24
2018-09-17
No

Hello, I'm trying to keep turbo vision for gentoo up-to-date. When I try to compile the current release rhtvision-2.2.1-4.tar.gz with gcc-7.3.0, I get this error:

g++  -I../include -I/usr/X11R6/include       -fPIC -O2 -pipe -march=bdver2 -mprefer-avx128 -mvzeroupper --std=c++98  -c ../classes/tdesktop.cc -o obj/tdesktop.lo
../classes/tdesktop.cc: In function ‘unsigned int iSqr(unsigned int)’:
../classes/tdesktop.cc:151:29: error: call of overloaded ‘abs(unsigned int)’ is ambiguous
     while( abs( res1 - res2 ) > 1 )
                             ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/cstdlib:75:0,
                 from ../classes/tdesktop.cc:16:
/usr/include/stdlib.h:722:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/cstdlib:77:0,
                 from ../classes/tdesktop.cc:16:
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/bits/std_abs.h:56:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^~~
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/bits/std_abs.h:61:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^~~
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/bits/std_abs.h:70:3: note: candidate: double std::abs(double)
   abs(double __x)
   ^~~
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/bits/std_abs.h:74:3: note: candidate: float std::abs(float)
   abs(float __x)
   ^~~
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/bits/std_abs.h:78:3: note: candidate: long double std::abs(long double)
   abs(long double __x)
   ^~~
make[1]: *** [librhtv.umk:1159: obj/tdesktop.lo] Error 1
make[1]: Leaving directory '/var/tmp/portage/dev-libs/tvision-2.2.1.4/work/tvision/makes'
make: *** [Makefile:28: dynamic-lib] Error 2

With gcc-6 it was possible to add a

using std::abs;

to the files where this error shows up. But with gcc-7 it is no longer possible to use abs with unsigned values.

As a workaround, I changed all the variables where this error pops up to int, which let's the compilation finish, but can't tell the impact this will have on apps using the library.

Discussion

  • Bernd Waibel

    Bernd Waibel - 2018-09-17

    See the following patch of where I had to add changes:

    diff --git a/classes/tdesktop.cc b/classes/tdesktop.cc
    index 38f1be4..041e0a0 100644
    --- a/classes/tdesktop.cc
    +++ b/classes/tdesktop.cc
    @@ -142,8 +142,8 @@ TBackground *TDeskTop::initBackground( TRect r )
     static
     unsigned iSqr( unsigned i )
     {
    -    unsigned res1 = 2;
    -    unsigned res2 = i/res1;
    +    int res1 = 2;
    +    int res2 = i/res1;
         while( abs( res1 - res2 ) > 1 )
             {
             res1 = (res1 + res2)/2;
    diff --git a/classes/tdisplay.cc b/classes/tdisplay.cc
    index 9225d48..fd44ecd 100644
    --- a/classes/tdisplay.cc
    +++ b/classes/tdisplay.cc
    @@ -360,10 +360,10 @@ void TDisplay::setArgv(int aArgc, char **aArgv, char **aEnvir)
      environment=aEnvir;
     }
    
    -Boolean TDisplay::searchClosestRes(TScreenResolution *res, unsigned x,
    -                                   unsigned y, unsigned cant, unsigned &pos)
    +Boolean TDisplay::searchClosestRes(TScreenResolution *res, int x,
    +                                   int y, unsigned cant, unsigned &pos)
     {
    - unsigned i, minDif, indexMin, dif;
    + int i, minDif, indexMin, dif;
      int firstXMatch=-1;
      // Look for an exact match of width
      for (i=0; i<cant && res[i].x<x; i++)
    diff --git a/classes/x11/x11src.cc b/classes/x11/x11src.cc
    index 538457e..13dbca2 100644
    --- a/classes/x11/x11src.cc
    +++ b/classes/x11/x11src.cc
    @@ -2536,7 +2536,7 @@ TScreenFont256 *TScreenX11::ChooseClosestFont(unsigned fW, unsigned fH)
         nFont=&font10x20;
      else
        {
    -    unsigned target=fW*fH;
    +    int target=fW*fH;
         int dif1=abs(8*16-target);
         int dif2=abs(10*20-target);
         if (dif1<dif2)
    diff --git a/include/tv/screen.h b/include/tv/screen.h
    index e143f1f..9e6a1b5 100644
    --- a/include/tv/screen.h
    +++ b/include/tv/screen.h
    @@ -30,7 +30,7 @@ struct TScreenFont256
    
     struct TScreenResolution
     {
    - unsigned x,y;
    + int x,y;
     };
    
     // Type for the callback called when the driver needs a new font.
    @@ -152,7 +152,7 @@ public:
      static Boolean  setDontMoveHiddenCursor(Boolean value);
      static Boolean  getDontMoveHiddenCursor() { return opts1 & DontMoveHiddenCursor ? True : False; };
      // Helper to look for the closest resolution from a list
    - static Boolean  searchClosestRes(TScreenResolution *res, unsigned x, unsigned y,
    + static Boolean  searchClosestRes(TScreenResolution *res, int x, int y,
                                       unsigned cant, unsigned &pos);
      // Returns the default palette
      static const TScreenColor *getDefaultPalette() { return PC_BIOSPalette; }
    
     
  • Bernd Waibel

    Bernd Waibel - 2018-11-07

    Is this project still alive?

     
  • Lorinczy Zsigmond

    I've just found the problem of 'abs'; I suggest using the following macro:
    #define abs_diff(i,j) ((i)>=(j)?(i)-(j):(j)-(i))

    Should interest arise, I could send patch(es).

     
    • Bernd Waibel

      Bernd Waibel - 2018-11-18

      Your macro looks cleaner then my changes to the datatype.
      If you like, you can create a PR against my fork of the project at https://sourceforge.net/u/waebbl/tvision/ci/master/tree/

       
  • Lorinczy Zsigmond

    Well, the version I downloaded from git does compile without this problem ( git clone https://git.code.sf.net/p/tvision/code tvision-code )

     
  • Bernd Waibel

    Bernd Waibel - 2018-11-25

    Thanks for the info, but this doesn't help me. I need to prepare a versioned build for gentoo, not a live build file. If you don't want to share your patches, I guess, I need to figure them out myself, or just use my patch.

     
  • Lorinczy Zsigmond

    Hi, I suggest you create a patch from git version based on version 2.2.1 (from files/UNIX/2.2.1 CVS20161117/rhtvision_2.2.1-4.tar.gz) -- I'am attaching sample patch.

     
  • Salvador Eduardo Tropea

    I think the following solves the problem, please confirm.
    Bernd Waibel: do you need a tarball?

     
  • Bernd Waibel

    Bernd Waibel - 2019-06-12

    Salvador Eduardo Tropea: Sorry for the delay. The patch works partly, I needed to add the equal abs definiton to classes/tdisplay.cc too, see the attached file.
    I don't need a tarball for this.

     
  • Bernd Waibel

    Bernd Waibel - 2019-06-27

    Actually a tar ball would be nice, as you have released a new release for this, which I noticed just today, but only with rpm release targets.

     
  • Salvador Eduardo Tropea

    I moved the repor to GitHub. SF Git browser has too many bugs and I have other projects at GitHub.
    https://github.com/set-soft/tvision
    Last release is 2.2.3 and compiles with gcc 10.2

     
  • Salvador Eduardo Tropea

    • status: open --> closed
    • assigned_to: Salvador Eduardo Tropea
     
  • Bernd Waibel

    Bernd Waibel - 2020-08-24

    Thanks for the move to github, this will help me a lot.

     

Log in to post a comment.