2012-04-26 87 views
2

我在編譯文件Mutex.h時遇到問題 - >它屬於庫STK(綜合工具包C++)。錯誤C4430,C2146 - 缺少類型說明符 - 假定爲int。注意:C++不支持default-int

我剛剛收錄了我需要的文件(「RtWvOut.h」,Mutex.h/cpp,Stk.h/cpp,WvOut.h),並在編譯期間消除了以下問題。 謝謝您的回答:)


d:\ KARI \ Mutex.h:67:錯誤:C2146:語法錯誤:缺少 ';'在標識符'mutex_'之前 d:\ kari \ Mutex.h:67:錯誤:C4430:缺少類型說明符 - 假定爲int。注意:C++不支持default-int d:\ kari \ Mutex.h:68:錯誤:C2146:語法錯誤:缺少';'在標識符'condition_'之前 d:\ kari \ Mutex.h:68:錯誤:C4430:缺少類型說明符 - 假定爲int。注意:C++不支持默認int


這裏是Mutex.h

#ifndef STK_MUTEX_H 
    #define STK_MUTEX_H 

    #include "Stk.h" 

    #if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)){ 

     #include <pthread.h> 
     typedef pthread_mutex_t MUTEX; 
     typedef pthread_cond_t CONDITION; 
    } 
    #elif defined(__OS_WINDOWS__){ 

     #include <windows.h> 
     #include <process.h> 
     typedef CRITICAL_SECTION MUTEX; 
     typedef HANDLE CONDITION; 
    } 
    #endif 

    namespace stk { 

    /**************************************************/ 
    /*! \class Mutex 
     \brief STK mutex class. 

     This class provides a uniform interface for 
     cross-platform mutex use. On Linux and IRIX 
     systems, the pthread library is used. Under 
     Windows, critical sections are used. 

     by Perry R. Cook and Gary P. Scavone, 1995-2011. 
    */ 
    /***************************************************/ 

    class Mutex : public Stk 
    { 
    public: 
     //! Default constructor. 
     Mutex(); 

     //! Class destructor. 
     ~Mutex(); 

     //! Lock the mutex. 
     void lock(void); 

     //! Unlock the mutex. 
     void unlock(void); 

     //! Wait indefinitely on the mutex condition variable. 
     /*! 
     The mutex must be locked before calling this function, and then 
     subsequently unlocked after this function returns. 
     */ 
     void wait(void); 

     //! Signal the condition variable. 
     /*! 
     The mutex must be locked before calling this function, and then 
       subsequently unlocked after this function returns. 
     */ 
     void signal(void); 

    protected: 

    MUTEX mutex_;     ##################x LINE 67 
    CONDITION condition_;   ################## LINE 68 

    }; 
    } // stk namespace 
    #endif 

的代碼和代碼Mutex.cpp

/***************************************************/ 
/*! \class Mutex 
    \brief STK mutex class. 

    This class provides a uniform interface for 
    cross-platform mutex use. On Linux and IRIX 
    systems, the pthread library is used. Under 
    Windows, critical sections are used. 

    by Perry R. Cook and Gary P. Scavone, 1995-2011. 
*/ 
/***************************************************/ 

#include "Mutex.h" 

namespace stk { 

Mutex :: Mutex() 
{ 

#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) 

    pthread_mutex_init(&mutex_, NULL); 
    pthread_cond_init(&condition_, NULL); 

#elif defined(__OS_WINDOWS__) 

    InitializeCriticalSection(&mutex_); 
    condition_ = CreateEvent(NULL, // no security 
          true, // manual-reset 
          false, // non-signaled initially 
          NULL); // unnamed 

#endif 
} 

Mutex :: ~Mutex() 
{ 
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) 

    pthread_mutex_destroy(&mutex_); 
    pthread_cond_destroy(&condition_); 

#elif defined(__OS_WINDOWS__) 

    DeleteCriticalSection(&mutex_); 
    CloseHandle(condition_); 

#endif 
} 

void Mutex :: lock() 
{ 
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) 

    pthread_mutex_lock(&mutex_); 

#elif defined(__OS_WINDOWS__) 

    EnterCriticalSection(&mutex_); 

#endif 
} 

void Mutex :: unlock() 
{ 
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) 

    pthread_mutex_unlock(&mutex_); 

#elif defined(__OS_WINDOWS__) 

    LeaveCriticalSection(&mutex_); 

#endif 
} 

void Mutex :: wait() 
{ 
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) 

    pthread_cond_wait(&condition_, &mutex_); 

#elif defined(__OS_WINDOWS__) 

    WaitForMultipleObjects(1, &condition_, false, INFINITE); 

#endif 
} 

void Mutex :: signal() 
{ 
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) 

    pthread_cond_signal(&condition_); 

#elif defined(__OS_WINDOWS__) 

    SetEvent(condition_); 

#endif 
} 
} // stk namespace 

和代碼,其中包括Mutex.h:(RtWvOut.h)

#ifndef STK_RTWVOUT_H 
#define STK_RTWVOUT_H 

#include "WvOut.h" 
#include "RtAudio.h" 
#include "Mutex.h" 

namespace stk { 

/***************************************************/ 
/*! \class RtWvOut 
    \brief STK realtime audio (blocking) output class. 

    This class provides a simplified interface to RtAudio for realtime 
    audio output. It is a subclass of WvOut. This class makes use of 
    RtAudio's callback functionality by creating a large ring-buffer 
    into which data is written. This class should not be used when 
    low-latency is desired. 

    RtWvOut supports multi-channel data in interleaved format. It is 
    important to distinguish the tick() method that outputs a single 
    sample to all channels in a sample frame from the overloaded one 
    that takes a reference to an StkFrames object for multi-channel 
    and/or multi-frame data. 

    by Perry R. Cook and Gary P. Scavone, 1995-2011. 
*/ 
/***************************************************/ 

class RtWvOut : public WvOut 
{ 
public: 

    //! Default constructor. 
    /*! 
    The default \e device argument value (zero) will select the 
    default output device on your system. The first device enumerated 
    by the underlying audio API is specified with a value of one. The 
    default buffer size of RT_BUFFER_SIZE is defined in Stk.h. An 
    StkError will be thrown if an error occurs duing instantiation. 
    */ 
    RtWvOut(unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), 
      int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20); 

    //! Class destructor. 
    ~RtWvOut(); 

    //! Start the audio output stream. 
    /*! 
    The stream is started automatically, if necessary, when a 
    tick() method is called. 
    */ 
    void start(void); 

    //! Stop the audio output stream. 
    /*! 
    It may be necessary to use this method to avoid undesireable 
    audio buffer cycling if you wish to temporarily stop audio output. 
    */ 
    void stop(void); 

    //! Output a single sample to all channels in a sample frame. 
    /*! 
    If the device is "stopped", it is "started". 
    */ 
    void tick(const StkFloat sample); 

    //! Output the StkFrames data. 
    /*! 
    If the device is "stopped", it is "started". The number of 
    channels in the StkFrames argument must equal the number of 
    channels specified during instantiation. However, this is only 
    checked if _STK_DEBUG_ is defined during compilation, in which 
    case an incompatibility will trigger an StkError exception. 
    */ 
    void tick(const StkFrames& frames); 

    // This function is not intended for general use but must be 
    // public for access from the audio callback function. 
    int readBuffer(void *buffer, unsigned int frameCount); 

protected: 

    RtAudio dac_; 
    Mutex mutex_; 
    bool stopped_; 
    unsigned int readIndex_; 
    unsigned int writeIndex_; 
    long framesFilled_; 
    unsigned int status_; // running = 0, emptying buffer = 1, finished = 2 

}; 

} // stk namespace 

#endif 
+0

錯誤表示「MUTEX」和「CONDITION」未定義。所以看起來你的系統上沒有宏__OS_IRIX__,__OS_LINUX__,__OS_MACOSX__和__OS_WINDOWS__。也許你需要在'#include「Mutex.h」'之前包含其他內容? – 2012-04-26 08:36:49

+0

是的,你是對的。現在,它的工作,謝謝:) – 2012-04-26 08:47:22

回答

2

您是否告訴它它在哪個平臺上運行?如果你看看這行代碼:

#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)){ 

你可以看到,它需要以某種方式告訴。有些東西必須定義適當的__OS_...標誌。

相關問題