问题
In Visual Studio, when you compile foo.idl, MIDL generates the proxy information in foo_p.c.
Unfortunately, for Win32 and x64 files, it uses the same filename. For Win32, the file starts with:
#if !defined(_M_IA64) && !defined(_M_AMD64)
For x64, the file starts with:
#if defined(_M_AMD64)
When you build for Win32 and then immediately build for x64, it doesn't replace the foo_p.c file, meaning that the project fails to link.
I tried having a pre-build event that deletes the foo_p.c file if it's for the wrong architecture, but VS doesn't even bother to run that step.
How should I get it so that I can build one configuration and then the other?
回答1:
You could modify the compiler settings for your IDL file to specify a different file name for the output proxy file according to the target platform. (Select Properties on the IDL file, then Configuration Properties / MIDL / Output).
- For Win32 builds, use
foo_p_w32.c
- For x64 builds, use
foo_p_x64.c
Then, in your Win32 project settings, exclude the file foo_p_x64.c
and vice versa for the x64 project.
You need to do the same for the _i.c file, otherwise Visual Studio doesn't seem to rebuild the IDL at all.
回答2:
Here are the configuration changes we use to allow automated builds to work cleanly
Change
<Tool
Name="VCMIDLTool"
TypeLibraryName="$(ProjectName).tlb"
OutputDirectory="$(SolutionDir)$(PlatformName)"
HeaderFileName="$(ProjectName)_h.h"
DLLDataFileName="$(ProjectName)_dlldata.c"
/>
To
<Tool
Name="VCMIDLTool"
TypeLibraryName="$(InputName).tlb"
OutputDirectory="$(SolutionDir)$(PlatformName)"
HeaderFileName="$(InputName)_i.h"
DLLDataFileName="$(InputName)_dlldata.c"
InterfaceIdentifierFileName="$(InputName)_i.c"
ProxyFileName="$(InputName)_p.c"
/>
and add $(SolutionDir)$(PlatformName) to your C++ Additional Include Directories
e.g.
<Tool Name="VCCLCompilerTool" ...
AdditionalIncludeDirectories="...;"$(SolutionDir)$(PlatformName);""
来源:https://stackoverflow.com/questions/221254/midl-generates-the-same-file-for-env-win32-and-env-win64