gpt4 book ai didi

c++ - 使用 FMOD 和 MinGW 编译项目时出现很多错误

转载 作者:行者123 更新时间:2023-11-30 04:21:04 25 4
gpt4 key购买 nike

我决定在我的项目中使用 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 兼容?

最佳答案

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

我从您提供的小代码中注意到了一些事情:

  • fmod() 实际上是一个函数,我可以想象一些编译器将其作为宏提供,这又与 #include 冲突,但这似乎不是您的问题。
  • 您同时包含 fmod.h 和 fmod.hpp,这看起来很可疑。
  • void ERRCHECK(FMOD_RESULT result); 看起来像是函数和宏的混合体。
  • play() 可能需要一个 const char* 数据

关于c++ - 使用 FMOD 和 MinGW 编译项目时出现很多错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14819627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com