使用FMD和MinGW编译项目时出现很多错误

时间:2013-02-11 19:44:41

标签: c++ mingw fmod

我决定在我的项目中使用FMOD进行声音播放,但是我遇到了很多编译错误,我不确定如何修复。

使用FMOD的类的头文件或多或少看起来像这样:

#ifndef PROJECTNAME_SOUNDMANAGER_H_
#define PROJECTNAME_SOUNDMANAGER_H_

#include <iostream>

#include <fmod.h>
#include <fmod.hpp>
#include <fmod_errors.h>

class SoundManager {
    public:
        static SoundManager &instance();
        void play(char *data, size_t size, bool loop=false);
        void stopAll();
    private:
        void ERRCHECK(FMOD_RESULT result);
        SoundManager() : mSystem(nullptr) {
            initFMOD();
        }
        SoundManager(const SoundManager &other);
        SoundManager &operator=(const SoundManager &other);
        void initFMOD();
        FMOD::System *mSystem;
        FMOD::Sound *mSound;
        FMOD::Channel *mSoundChannel;
};

#endif // PROJECTNAME_SOUNDMANAGER_H_

以下是一些编译错误:

...../api/inc/fmod.h:1054:33: error: expected ')' before '*' token
...../api/inc/fmod.h:1056:33: error: expected ')' before '*' token
...../api/inc/fmod.h:1058:33: error: expected ')' before '*' token
...../api/inc/fmod.h:1059:33: error: expected ')' before '*' token
.....
...../api/inc/fmod.h:1465:5: error: 'FMOD_SOUND_PCMREADCALLBACK' does not name a type
...../api/inc/fmod.h:1466:5: error: 'FMOD_SOUND_PCMSETPOSCALLBACK' does not name a type
...../api/inc/fmod.h:1467:5: error: 'FMOD_SOUND_NONBLOCKCALLBACK' does not name a type
...../api/inc/fmod.h:1473:5: error: 'FMOD_FILE_OPENCALLBACK' does not name a type
.....
...../api/inc/fmod.h:1828:19: error: expected initializer before 'FMOD_Memory_GetStats'
...../api/inc/fmod.h:1829:19: error: expected initializer before 'FMOD_Debug_SetLevel'
...../api/inc/fmod.h:1830:19: error: expected initializer before 'FMOD_Debug_GetLevel'
...../api/inc/fmod.h:1831:19: error: expected initializer before 'FMOD_File_SetDiskBusy'
.....
...../api/inc/fmod.hpp:59:21: error: expected ';' at end of member declaration
...../api/inc/fmod.hpp:59:51: error: ISO C++ forbids declaration of 'release' with no type [-fpermissive]
...../api/inc/fmod.hpp:62:21: error: expected ';' at end of member declaration
...../api/inc/fmod.hpp:62:21: error: declaration of 'FMOD_RESULT FMOD::System::_stdcall'
...../api/inc/fmod.hpp:59:21: error: conflicts with previous declaration 'FMOD_RESULT FMOD::System::_stdcall'
...../api/inc/fmod.hpp:62:73: error: ISO C++ forbids declaration of 'setOutput' with no type [-fpermissive]
...../api/inc/fmod.hpp:63:21: error: expected ';' at end of member declaration
...../api/inc/fmod.hpp:63:21: error: declaration of 'FMOD_RESULT FMOD::System::_stdcall'
...../api/inc/fmod.hpp:59:21: error: conflicts with previous declaration 'FMOD_RESULT FMOD::System::_stdcall'
.....

如果有任何不同,我正在使用-std=c++0x进行编译。

我尝试过搜索,但我无法找到任何可以帮助我解决这些错误的内容。

请注意我使用的是FMOD Ex 4.44.06。

编辑:我似乎发现了这个问题。当我创建一个最小的例子并在没有-std=c++0x的情况下编译它时,一切都编译得很好。但是,如果我添加该标志,我会得到与此项目相同的错误。有没有办法让FMOD在C ++ 11中发挥出色?

2 个答案:

答案 0 :(得分:2)

我的猜测是有一些定义为宏或未定义为宏的东西。现在,您的任务是提供一个最小的示例。这可能意味着手动删除大量代码或从头文件中复制代码。这样做,直到您可以提供几行违规代码。我想这样做,你会发现问题。

我注意到你提供的小代码有几件事情:

  • fmod()实际上是一个函数,我可以想象一些编译器将它作为宏提供,而这反过来与#include冲突,但这似乎不是你的问题。
  • 你包括fmod.h和fmod.hpp,它们看起来很可疑。
  • void ERRCHECK(FMOD_RESULT result);看起来像是功能和宏之间的混合。
  • play()应该选择const char* data

答案 1 :(得分:0)

在MSYS2和GCC v5.4.0下,我遇到了同样的问题。 解决方案是添加编译标记-D__CYGWIN32__

这是由于fmod.h中的以下内容:

#if defined(__CYGWIN32__)
    #define F_CDECL __cdecl
    #define F_STDCALL __stdcall
    #define F_DECLSPEC __declspec
    #define F_DLLEXPORT ( dllexport )
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
    #define F_CDECL _cdecl
    #define F_STDCALL _stdcall
    #define F_DECLSPEC __declspec
    #define F_DLLEXPORT ( dllexport )
...
相关问题