[gdal-dev] Patch to improve libjpeg compatibility on gdal 1.11

Even Rouault even.rouault at spatialys.com
Wed Feb 18 02:24:48 PST 2015


Le mercredi 18 février 2015 11:04:32, David Weiß a écrit :
> Hey Even,
> 
> > Where I'm confused now is that I don't need any patch in the 1.11 branch
> > to compile against 9a...
> > 
> > The releavant extract of the output of g++ -E on libjpeg_io.cpp is {{{ #
> > 309 "/home/even/install-jpeg-9a/include/jmorecfg.h"
> > typedef int boolean;
> > }}}
> > 
> > so it doesn't use at all the "typedef enum { FALSE = 0, TRUE = 1 }
> > boolean;" thing.
> 
> Maybe GCC doesn't because of line 307:
> 	#if defined FALSE || defined TRUE || defined QGLOBAL_H
> 
> But MSVC fails to have one of these defined and thus uses the else-case:
> 	#else
> 	typedef enum { FALSE = 0, TRUE = 1 } boolean;
> 
> Should have mentioned that the problem occurred building with MS VS 2010.

David,

Hum, I've tried to replicate a minimalistic version of libjpeg_io.cpp:


"""
namespace PCIDSK
{
};

#include "cpl_port.h"

using namespace PCIDSK;

extern "C" {
typedef enum { FALSE = 0, TRUE = 1 } boolean;
}
"""

The above fails to compile because cpl_port.h contains:
"""
#ifndef FALSE
#  define FALSE 0
#endif

#ifndef TRUE
#  define TRUE  1
#endif
"""

With gcc 4.4 :
test.cc:10: error: expected identifier before numeric constant
test.cc:10: error: expected ‘}’ before numeric constant
test.cc:10: error: expected unqualified-id before numeric constant
test.cc:10: error: expected constructor, destructor, or type conversion before 
‘;’ token
test.cc:11: error: expected declaration before ‘}’ token

With clang 3.2:
test.cc:10:16: error: expected '}'
typedef enum { FALSE = 0, TRUE = 1 } boolean;
               ^
port/cpl_port.h:326:17: note: expanded from macro 'FALSE'
#  define FALSE 0
                ^
test.cc:10:14: note: to match this '{'
typedef enum { FALSE = 0, TRUE = 1 } boolean;
             ^
1 error generated.

With VS 2008:
test.cc(10) : error C2143: syntax error : missing '}' before 'constant'
test.cc(10) : error C2143: syntax error : missing ';' before '}'
test.cc(10) : error C4430: missing type specifier - int assumed. Note: C++ does 
not support default-int
test.cc(11) : error C2059: syntax error : '}'
test.cc(11) : error C2143: syntax error : missing ';' before '}'
test.cc(11) : error C2059: syntax error : '}'


I'm also not completely convinced by the fact that "typedef boolean as enum 
with values TRUE and FALSE, which do not propagate into other namespace"

The following small experiment (with "include cpl_port.h" commented) compiles 
fine :

"""
namespace PCIDSK
{
    int foo();
};

//#include "cpl_port.h"

using namespace PCIDSK;

extern "C" {
typedef enum { FALSE = 0, TRUE = 1 } boolean;
}

int PCIDSK::foo()
{
    return TRUE;
}
"""

I must certainly miss something...

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list