VC编译错误:'waveformat_tag' : 'struct' type redefinition

来源:互联网 发布:1分钟的自我介绍 知乎 编辑:程序博客网 时间:2024/05/17 23:16

错误信息:

: error C2011: 'waveformat_tag' : 'struct' type redefinition
: error C2011: 'pcmwaveformat_tag' : 'struct' type redefinition
 : error C2061: syntax error : identifier 'LPCWAVEFORMATEX'
 : error C2061: syntax error : identifier 'LPCWAVEFORMATEX'

解决方法:

        这是头文件包含顺序不正确所致。原先的文件包含顺序为:

#include <mmreg.h>
#include <mmsystem.h>
#include <msacm.h>

        可以看到,mmreg.h文件中有如下定义:

#ifndef WAVE_FORMAT_PCM

typedef struct waveformat_tag ××××

        而WAVE_FORMAT_PCM在mmsystem.h中有定义,但是在#include <mmreg.h>之前,WAVE_FORMAT_PCM还是没有被定义,所以,typedef struct waveformat_tag ××××语句生效,之后mmsystem.h中再次定义waveformat_tag,于是出现重复定义。

        正确的包含顺序是:

#include <mmsystem.h>
#include <mmreg.h>
#include <msacm.h>

(包含静态库)
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "Msacm32.lib")