Opened 18 years ago

Closed 18 years ago

#1885 closed defect (fixed)

Mac OS X compile error with abs(long long)

Reported by: Nigel Owned by: Nigel
Priority: minor Milestone: 0.20
Component: mythtv Version: head
Severity: medium Keywords: OSX media monitor mtd
Cc: nigel@… Ticket locked: no

Description (last modified by Nigel)

My first backend build in a while does:

g++ -c -pipe -mcpu=7450 -mtune=7450 -mpowerpc-gfxopt -faltivec -Wall -W -O3 -Wall -Wno-switch -I/Volumes/MythOSXbuild/.osx-packager/build/include -no-cpp-precomp -pipe -fomit-frame-pointer -force_cpusubtype_ALL -Wno-sign-compare -fno-inline-functions  -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DPREFIX=\"/Volumes/MythOSXbuild/.osx-packager/build\" -DLIBDIR=\"/Volumes/MythOSXbuild/.osx-packager/build/lib\" -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_ACCESSIBILITY_SUPPORT -I/Volumes/MythOSXbuild/.osx-packager/src/qt-mac-free-3.3.5/mkspecs/default -I. -I../../../../../build/include -I../../../../../build/include -I../../libs -I../../libs/libmyth -I../../libs/libmythtv -I../.. -I../../libs/libavutil -I../../libs/libavformat -I../../libs/libavcodec -I/Volumes/MythOSXbuild/.osx-packager/src/qt-mac-free-3.3.5/include -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Versions/A/Headers -o mainserver.o mainserver.cpp
In file included from mainserver.h:17,
                 from mainserver.cpp:41:
filetransfer.h:19: warning: `class FileTransfer' only defines a private 
   destructor and has no friends
mainserver.cpp: In member function `void 
   MainServer::FillStatusXML(QDomDocument*)':
mainserver.cpp:3998: error: call of overloaded `abs(long long int)' is 
   ambiguous
/usr/include/stdlib.h:126: error: candidates are: int abs(int)
/usr/include/gcc/darwin/3.3/c++/cmath:95: error:                 long double 
   std::abs(long double)
/usr/include/gcc/darwin/3.3/c++/cmath:91: error:                 float 
   std::abs(float)
/usr/include/gcc/darwin/3.3/c++/cmath:87: error:                 double 
   std::abs(double)
/usr/include/gcc/darwin/3.3/c++/cstdlib:119: error:                 long int 
   std::abs(long int)
make[2]: *** [mainserver.o] Error 1}}}

Change History (6)

comment:1 Changed 18 years ago by Nigel

Description: modified (diff)

comment:2 Changed 18 years ago by awk@…

Cc: nigel@… added
Keywords: OSX media monitor mtd added

Nigel,

Which rev have you tried - I synced to R10023 Saturday afternoon and did a full build without problems.

Also have you updated to the new XCode tools package released last week ? I have not done that yet. It's possible a compiler/header change in that update causes this.

comment:3 Changed 18 years ago by Nigel

Status: newassigned

Rev 9471 succeds, 9472 or later fails. This is on 10.3.9, which uses GCC 3.3. On a later machine (Intel Mac, GCC 4.0.1) there is no such error.
Changing the abs() to an llabs() fixes the error, but causes a similar "overloaded function" error on the Intel Mac or Linux, so I suspect this is a GCC 3 headers issue.

comment:4 Changed 18 years ago by danielk

gcc handles abs() as a built-in function. So even if the cmath header is good, if gcc was compiled incorrectly it could be missing abs(long long int). If this happens with the Apple distributed version of gcc, ifdef's might be a reasonable solution.

comment:5 Changed 18 years ago by Nigel

This illustrates the problem:

#include <cstdlib>
use namespace std;

int main()
{
    long long test = -1;

    if ( abs(test) > 1 )
        exit(-1)

    exit(0);
}

On any GCC 3.3 machine (My Mac, Sparc Solaris, et c.) it gives the error when the namespace line is there, but not if it is commented out. I am guessing that only after 3.3 they decided to have a decent set of std:: overloads, but then they stupidly also added an llabs() in the same place.
I was hoping that something simple like casting to a double would work, but surprize-surprise, that is ambiguously overloaded in GCC4 or later (in thye same way that llabs() is).
#ifdef GCC_VERSION is just too ugly - I think I will define a local myAbs() instead?

comment:6 Changed 18 years ago by Nigel

Resolution: fixed
Status: assignedclosed

(In [10073]) Workaround for GCC3 abs(long long) problem. Closes #1885

Note: See TracTickets for help on using tickets.