2013-02-11 93 views
1

我决定在我的项目中使用FMOD进行声音播放,但是我收到了很多编译器错误,我不确定如何解决。使用FMG编译项目时出现很多错误使用MinGW

使用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中表现出色吗?

+0

什么*第一个*错误? C++错误倾向于级联,并且如果在包含此文件之前出现问题*可能会有许多错误作为第一个错误的副作用。一个常见的罪魁祸首是在类定义的末尾丢失分号。 – molbdnilo 2013-02-11 19:59:13

+0

@molbdnilo对不起,我不清楚,打印的第一个错误是你在我的帖子中看到的第一个错误。 – Merigrim 2013-02-11 20:05:08

+0

我下载了4.44.06,那些行号完全不符合我的fmod.h。例如,1054-1056是一个评论。 – molbdnilo 2013-02-11 20:41:30

回答

2

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

有我与你提供的一些代码注意到几件事情:)

  • FMOD(实际上是一个功能,我可以想像一些编译器提供这个宏,它与#反过来冲突包括,但这似乎不是你的问题。
  • 您同时包含fmod.h和fmod.hpp,这看起来很可疑。
  • void ERRCHECK(FMOD_RESULT result);看起来像功能和宏之间的混合。
  • play()应该可能需要一个const char* data
+1

我试着制作一个测试文件,只包含FMOD头文件和其他东西,但令我惊讶的是它已编译!然而,当我除了标题包含除去FMOD的所有引用的违规类别时,我仍然得到相同的错误。嗯...我会进一步调查。为了解决你的观点,fmod.hpp包含了fmod.h,所以这不是问题。即使我删除了fmod.h include,我仍然得到相同的错误。 ERRCHECK只是一个函数,但我承认它可能有一个更好的名称。 play()应该确实需要一个const char *。谢谢! – Merigrim 2013-02-11 21:04:22

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) 
...