[英]How to force MIDL compiler to use “C++ mode” instead of “C mode” in Visual Studio 2010?
我的問題很簡單,但我不知道如何解決它:我有一個帶有idl文件的Visual Studio 2010項目,用於生成COM類型庫。 該項目最初由VC ++ 6.0創建。 VC 6.0可以編譯該項目而不會出現任何錯誤。 但我最近轉換它並繼續嘗試在VC 2010中編譯它。我總是得到以下控制台輸出消息:
1>------ Build started: Project: myProject, Configuration: Debug Win32 ------
1>Build started 08.04.2013 11:23:12.
1>InitializeBuildStatus:
1> Touching ".\Debug\myProject.unsuccessfulbuild".
1>Midl:
1> Processing .\myFile.idl
1> myProject.idl
1>C:\Programme\Microsoft Visual Studio 10.0\VC\include\typeinfo(29): fatal error C1189: #error : This header requires a C++ compiler ...
1>
1>midl : command line error MIDL1003: error returned by the C preprocessor (2)
1>
1>Build FAILED.
我已經發現這只是意味着,MIDL以“C模式”調用編譯器,而不是“C ++模式”。 該項目既不包含.c也不包含.cpp,只包含.h和.idl文件:C / C ++部分在項目屬性頁面中不可用。 我嘗試添加一個dummy.cpp文件,使缺少的部分可用,並能夠在其中默認C ++編譯器。
Midl文件看起來像:
import "unknwn.idl";
//Globale Definitionen
#include "MyProjectGlobaleDefinitionen.h"
//Interfacedeklarationen
interface IMyProjectDcomSchnittstellen;
[
uuid(E6C14CB3-CFFE-11d4-B1A2-00104BC1A971),
helpstring(MyProject_SCHNITTSTELLE_RELEASE_2_HELPSTRING),
version (MyProject_SCHNITTSTELLE_VERSIONSNUMMER)
]
library MyProject_SCHNITTSTELLE_KURZBEZEICHNER
{
importlib("..\\..\\..\\Files\\DLL\\stdole32.tlb");
importlib("..\\..\\..\\Files\\DLL\\MSADO15.dll");
// #include "..\..\common\Hresult_Werte.h"
#include "MyProjectDcomSchnittstellenTypdefinitionen.idl"
#include "IObj1ManagerMyProject.idl"
#include "IObj1ManagerMyProjectEvents.idl"
#include "IObj2Manager.idl"
#include "IObj2NotifySink.idl"
//************ Obj2Manager **************************
[uuid(F0284CF2-8E24-11d4-8941-006097AA387A)]
coclass Obj2Manager
{
[default] interface IObj2Manager;
[default, source] interface IObj2NotifySinkEvents;
}
//************ Obj1ManagerMyProject ************************
[uuid(E6C14CB2-CFFE-11d4-B1A2-00104BC1A971)]
coclass Obj1ManagerMyProject
{
[default] interface IObj1ManagerMyProject;
[default, source] interface IObj1ManagerMyProjectEvents;
}
}; //Ende library Obj1_myProject
如何強制MIDL以“C ++模式”調用編譯器/預處理器?
不應該這樣
#include "MyProjectDcomSchnittstellenTypdefinitionen.idl"
#include "IObj1ManagerMyProject.idl"
#include "IObj1ManagerMyProjectEvents.idl"
#include "IObj2Manager.idl"
#include "IObj2NotifySink.idl"
實際上就是這樣
import "MyProjectDcomSchnittstellenTypdefinitionen.idl"
import "IObj1ManagerMyProject.idl"
import "IObj1ManagerMyProjectEvents.idl"
import "IObj2Manager.idl"
import "IObj2NotifySink.idl"
好的...... 這個怎么樣:
此頁面僅適用於有特定理由將Microsoft C / C ++預處理器替換為MIDL使用的預處理器的開發人員,或僅適用於必須指定自定義預處理器開關的開發人員的開發人員。 MIDL開關/ cpp_cmd,/ cpp_opt和/ no_cpp用於覆蓋編譯器的默認行為。 通常沒有理由替換Microsoft C / C ++預處理器,也沒有理由指定自定義預處理器開關。
MIDL編譯器在初始處理IDL文件期間使用C預處理器。 編譯IDL文件時使用的構建環境與默認的C / C ++預處理器相關聯。 如果要使用不同的預處理器,MIDL編譯器開關/ cpp_cmd將啟用默認C / C ++ - 預處理器名稱的覆蓋:
midl /cpp_cmd preprocessor_name filename
在包含文件MyProjectGlobaleDefinitionen.h
有一個包含存在。 我只需刪除這個包含,因為它根本不需要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.