Clang, GCC and the kdegames4 port
iandw.au at gmail.com
Sat Dec 31 20:13:31 PST 2011
Using OS X Lion 10.7.2, Xcode 4.2.1 and Macports 2.0.3, I uninstalled
all my existing ports, following the Migration procedure, then I installed
the qt4-mac, kdelibs4 and kdegames4 ports (and dependencies).
kdegames4 failed to compile with Clang, which diagnosed source code
errors in two code files, quite correctly IMO. I bludgeoned the build into
submission with repeated edits of Macports' transient copy of the source
code and eventually got a successful build with Clang (I am a KDE Games
developer and know that code base reasonably well).
The kdegames4 code compiles successfully, without alteration, if you use
configure.compiler=llvm-gcc-4.2, i.e. Clang found real coding errors which
GCC does not find and has not found over several years of KDE releases.
The errors have had no effect on code at run time.
I went back to the KDE Games list to get to the bottom of the problem and
the situation is this:
- In both cases, the errors were to do with code that is declared and defined
in full in a C++ class in a header file, so the code is not actually compiled
until it is included in some *.cpp file.
- It appears that Clang and GCC handle headers and includes differently
and perhaps that Clang does more syntactic and semantic analysis of
headers, whereas GCC scans the headers but only compiles the methods
that are used in the *.cpp file and does not care if they are declared out
- In one case, in KDE Games, there is a method in a header that still
contains legacy Qt 3 code, but no *.cpp files use that particular method
and GCC lets it pass. In the other, a header uses a stdlib function whose
declaration has not yet been included in the *.cpp file. It can be corrected
by changing the order of the includes in the *.cpp file.
- Both errors will get fixed, but not until KDE SC 4.8.1 at least. The release
of KDE SC 4.8.0 is in its last stages ATM.
- There will be no further releases of KDE SC 4.7. Release 4.7.4 is the last.
The KDE release guys have decided that.
- So, if the port of kdegames4 @4.7.4 or @4.8.0 is to compile with Clang within
the next six months or so, it will be necessary to patch it at the Macports end.
I can provide the patch, if required.
I thought I should tell the list the above for general info re the transition from GCC
to Clang. It looks as though Clang does a more thorough job in some ways.
Should I submit a ticket and include the patch?
Cheers, Ian W.
More information about the macports-users