1

When upgrading my code to support ARM64, I received the error

'Typedef redefinition with different types ('signed char' vs 'bool')'

The code it refers to is;

#ifndef _WINDEF_
    // if these aren't defined already by Windows headers, define now

    typedef signed char BOOL;

    #define FALSE   0
    #define TRUE    1

#endif 

Struggling to see how I can resolve this?

I am using SoundTouch, the file is STTypes.h

Here is full code from that file;

#ifndef STTypes_H
#define STTypes_H

typedef unsigned int    uint;
typedef unsigned long   ulong;


#ifdef __GNUC__
    // In GCC, include soundtouch_config.h made by config scritps
    #include "soundtouch_config.h"
#endif

#ifndef _WINDEF_
    // if these aren't defined already by Windows headers, define now

    typedef signed char BOOL;

    #define FALSE   0
    #define TRUE    1

#endif  // _WINDEF_


namespace soundtouch
{

/// Activate these undef's to overrule the possible sampletype 
/// setting inherited from some other header file:
//#undef SOUNDTOUCH_INTEGER_SAMPLES
//#undef SOUNDTOUCH_FLOAT_SAMPLES

#if !(SOUNDTOUCH_INTEGER_SAMPLES || SOUNDTOUCH_FLOAT_SAMPLES)

    /// Choose either 32bit floating point or 16bit integer sampletype
    /// by choosing one of the following defines, unless this selection 
    /// has already been done in some other file.
    ////
    /// Notes:
    /// - In Windows environment, choose the sample format with the
    ///   following defines.
    /// - In GNU environment, the floating point samples are used by 
    ///   default, but integer samples can be chosen by giving the 
    ///   following switch to the configure script:
    ///       ./configure --enable-integer-samples
    ///   However, if you still prefer to select the sample format here 
    ///   also in GNU environment, then please #undef the INTEGER_SAMPLE
    ///   and FLOAT_SAMPLE defines first as in comments above.
    #define SOUNDTOUCH_INTEGER_SAMPLES     1    //< 16bit integer samples
    //#define SOUNDTOUCH_FLOAT_SAMPLES       1    //< 32bit float samples

 #endif

    #if (WIN32 || __i386__ || __x86_64__)
        /// Define this to allow X86-specific assembler/intrinsic optimizations. 
        /// Notice that library contains also usual C++ versions of each of these
        /// these routines, so if you're having difficulties getting the optimized 
        /// routines compiled for whatever reason, you may disable these optimizations 
        /// to make the library compile.

        #define SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS     1

    #endif

    // If defined, allows the SIMD-optimized routines to take minor shortcuts 
    // for improved performance. Undefine to require faithfully similar SIMD 
    // calculations as in normal C implementation.
    #define SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION    1


    #ifdef SOUNDTOUCH_INTEGER_SAMPLES
        // 16bit integer sample type
        typedef short SAMPLETYPE;
        // data type for sample accumulation: Use 32bit integer to prevent overflows
        typedef long  LONG_SAMPLETYPE;

        #ifdef SOUNDTOUCH_FLOAT_SAMPLES
            // check that only one sample type is defined
            #error "conflicting sample types defined"
        #endif // SOUNDTOUCH_FLOAT_SAMPLES

        #ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
            // Allow MMX optimizations
            #define SOUNDTOUCH_ALLOW_MMX   1
        #endif

    #else

        // floating point samples
        typedef float  SAMPLETYPE;
        // data type for sample accumulation: Use double to utilize full precision.
        typedef double LONG_SAMPLETYPE;

        #ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
            // Allow SSE optimizations
            #define SOUNDTOUCH_ALLOW_SSE       1
        #endif

    #endif  // SOUNDTOUCH_INTEGER_SAMPLES
};


// When this #define is active, eliminates a clicking sound when the "rate" or "pitch" 
// parameter setting crosses from value <1 to >=1 or vice versa during processing. 
// Default is off as such crossover is untypical case and involves a slight sound 
// quality compromise.
//#define SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER   1

#endif

/// OK I now have the answer, for anyone who has a similar issue use;

#ifndef _WINDEF_
    // if these aren't defined already by Windows headers, define now

#if defined(__APPLE__)
#if !defined(OBJC_HIDE_64) && TARGET_OS_IPHONE && __LP64__
typedef bool BOOL;
#else
typedef signed char BOOL;
// BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
// even if -funsigned-char is used.
#endif
#else
   typedef int BOOL;
#endif 

    #define FALSE   0
    #define TRUE    1

#endif  // _WINDEF_

I must credit this to rspeyer on Github for posting the new fix

https://github.com/talko/soundtouch/blob/9e06779ad056ad341dd369d4809ef20de95e4844/include/STTypes.h

Hypergater
  • 559
  • 1
  • 5
  • 15

2 Answers2

0

It looks to me like you have a project with mixed C++ and Objective-C and a .m file is including that header file, which is declaring a C++ namespace.

That will never work, so you will need to either avoid the .m file ever including that header file, or change it to .mm (Objective-C++).

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • Hi trojanfoe, I am unsure how I can locate the .m file in question, I tried searching to see, but cannot seem to find any .m file being imported? – Hypergater Jul 15 '15 at 16:24
  • @Hypergater The build log in Xcode will show the name of the file it was compiling at the time of the error. – trojanfoe Jul 15 '15 at 16:24
  • Oddly it works perfectly when ARM64 is removed from the build options? – Hypergater Jul 15 '15 at 16:25
  • @Hypergater Hmmm, that is odd. Can you confirm my suspicion of the mixed-language project (this includes using a C++ library)? – trojanfoe Jul 15 '15 at 16:26
  • It does have .cpp files inside yes – Hypergater Jul 15 '15 at 16:31
  • @Hypergater OK, then this subject is well covered on this site. It can be fairly complicated to mix the two languages, and my answer doesn't adequately cover a solution. However it should give you a clue. I cannot explain why it only causes an error when building for `ARM64`, however it's wrong regardless of the architecture. – trojanfoe Jul 15 '15 at 16:36
  • now fixed - I have edited my answer - thanks for your time however is still appreciated :) – Hypergater Jul 15 '15 at 16:49
0

Answer now added, fixes thanks to rspeyer on Github

https://github.com/talko/soundtouch/blob/9e06779ad056ad341dd369d4809ef20de95e4844/include/STTypes.h

Hypergater
  • 559
  • 1
  • 5
  • 15