如何解决这些编译器错误?

时间:2010-04-03 14:07:16

标签: c++

我有2001年的this源代码,我想编译。

它给出了这个:

$ make
g++ -O99 -Wall -DLINUX -pedantic   -c -o audio.o audio.cpp
In file included from audio.cpp:7:
audio.h:14: error: use of enum ‘mad_flow’ without previous declaration
audio.h:15: error: use of enum ‘mad_flow’ without previous declaration
audio.h:17: error: use of enum ‘mad_flow’ without previous declaration
audio.cpp: In function ‘mad_flow audio::input(void*, mad_stream*)’:
audio.cpp:19: error: new declaration ‘mad_flow audio::input(void*, mad_stream*)’
audio.h:14: error: ambiguates old declaration ‘int audio::input(void*, mad_stream*)’
audio.h:11: error: ‘size_t audio::stream::BufferPos’ is private
audio.cpp:23: error: within this context
audio.h:11: error: ‘size_t audio::stream::BufferSize’ is private
audio.cpp:23: error: within this context
audio.h:10: error: ‘char* audio::stream::Buffer’ is private
audio.cpp:26: error: within this context
audio.h:11: error: ‘size_t audio::stream::BufferSize’ is private
audio.cpp:26: error: within this context
audio.h:11: error: ‘size_t audio::stream::BufferPos’ is private
audio.cpp:27: error: within this context
audio.h:11: error: ‘size_t audio::stream::BufferSize’ is private
audio.cpp:27: error: within this context
audio.cpp: In function ‘mad_flow audio::output(void*, const mad_header*, mad_pcm*)’:
audio.cpp:49: error: new declaration ‘mad_flow audio::output(void*, const mad_header*, mad_pcm*)’
audio.h:15: error: ambiguates old declaration ‘int audio::output(void*, const mad_header*, mad_pcm*)’
audio.cpp: In function ‘mad_flow audio::error(void*, mad_stream*, mad_frame*)’:
audio.cpp:83: error: new declaration ‘mad_flow audio::error(void*, mad_stream*, mad_frame*)’
audio.h:17: error: ambiguates old declaration ‘int audio::error(void*, mad_stream*, mad_frame*)’
audio.cpp: In constructor ‘audio::stream::stream(const char*)’:
audio.cpp:119: error: ‘input’ was not declared in this scope
audio.cpp:122: error: ‘output’ was not declared in this scope
audio.cpp:123: error: ‘error’ was not declared in this scope
make: *** [audio.o] Error 1

audio.h包含

#ifndef _AUDIO_H_
#define _AUDIO_H_

#include <stdlib.h>
#include "mad.h"

namespace audio {
  class stream {
  private:
    char* Buffer;
    size_t BufferSize, BufferPos;
    struct mad_decoder Decoder;

    friend enum mad_flow input(void* Data, struct mad_stream* MadStream);
    friend enum mad_flow output(void* Data, const struct mad_header* Header,
                struct mad_pcm* PCM);
    friend enum mad_flow error(void* Data, struct mad_stream* MadStream,
                   struct mad_frame* Frame);

  public:
    stream(const char* FileName);
    ~stream();

    void play();
  };
}

#endif

更新

问题是mad_flow无法看到。如果我查看mad.h,则会在那里声明mad_flow

如果我只是复制/粘贴

  enum mad_flow {
    MAD_FLOW_CONTINUE = 0x0000,
    MAD_FLOW_STOP     = 0x0010,
    MAD_FLOW_BREAK    = 0x0011,
    MAD_FLOW_IGNORE   = 0x0020
  };
来自mad.h

错误消失(并发生新错误)。

那么如何让mad_flow可用?

2 个答案:

答案 0 :(得分:2)

关于:

  

我试图插入

enum mad_flow {};

...类型mad_flow的正确前向声明将是:

enum mad_flow ;

但你真的应该问自己为什么声明或定义不可见,因为前向声明可能是一个小问题。是否包括所有必要的标题?

<强> [--- ---编辑

在回应Johannes Schaub的评论时,这是一个前瞻性枚举的可编辑的例子:

enum mad_flow ;             // forward declaration

void f( mad_flow& arg ) ;   // forward declaration of function 
                            // using incomplete type

int main()
{
    mad_flow x ;            // Declaration using incomplete type

    f( x ) ;                // Function call using incomplete enum object
}

enum mad_flow               // Completion of the definition
{
    VALUE1,
    VALUE2
} ;

void f( mad_flow& arg )
{
    arg = VALUE1 ;          // Use of value from complete definition
}

答案 1 :(得分:1)

我从https://docs.google.com/leaf?id=0BzqFMbU_9R0YMDI5ZjYzNDAtMTNkZC00YzYwLWE3N2UtYTFmNjdlM2ZiYTg5&hl=en_GB下载了源档案。在INSTALL中,它说:

  

你需要libpng&gt; = 1.0.6,esound-devel和Mesa&gt; = 3.3来编译它。   这些可以在<URI:http://home.online.no/~loop/tsunami.html>找到。   未来的更新也可以在这里找到。

     

请:
      make all

     

执行命令
      ./demo

因此,在运行make all之前,请确保拥有所有依赖项。遗憾的是,INSTALL文件中提供的网址是一个损坏的链接,因此您必须尝试在网络上的其他位置查找列出的依赖关系。