When trying to compile a .dll, I'm getting an error with the interface keyword

流过昼夜 提交于 2019-12-22 10:38:04

问题


I have set up a project in Visual Studio to create a .dll. I have included an external library in the project which uses the keyword "interface". This is giving me the following error:

error C2146: syntax error : missing ';' before identifier 'INuiAudioBeam'

These are the lines of code where the error occurs:

#ifndef __INuiAudioBeam_FWD_DEFINED__
#define __INuiAudioBeam_FWD_DEFINED__
typedef interface INuiAudioBeam INuiAudioBeam; //Error on this line
#endif

The above code is part of a header file in the external library I have included. The project builds successfully without any errors when compiling without including the headers for the library (Note: Linking the library does not cause any problems).

What is the solution to this? Is it because I have an external library I'm using to create my dll? Should I create a .lib instead of a dll?


回答1:


If anyone else searches this, the problem is most likely

#define WIN32_LEAN_AND_MEAN

Before

#include <windows.h>

Remove the define, make sure your including windows.h, and that should define interface keyword for you




回答2:


You can get C2146 with indictment of the interface keyword. It may be confusing as to how a keyword may be undefined, especially that in other compilation units or projects that use the same header file - the inclusion of which brought about the problem - all goes smooth. However, the apparent keyword "interface" is still a compiler #define directive. It just happens to be buried inside a header file that a few developers have reasons to inspect: the <objbase.h>. There it is defined in two steps:

#define __STRUCT__ struct
#define interface __STRUCT__

Since the <objbase.h> is included by multiple other header files - such as ole2.h, oleauto.h, and a slew of ATL headers - you may be surprised with this error when none of those headers were included in the current compilation unit.



来源:https://stackoverflow.com/questions/18298403/when-trying-to-compile-a-dll-im-getting-an-error-with-the-interface-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!