My current project involves building a lot of executable files, each
with custom settings in a header that uses the project configuration:
#ifdef _FOO1
#define bar foobaz
#define foo foobar
#endif
_FOO1 is defined via the project configuration.
Within this, I would like to add a #define OUTPUT_FILE "FOO1.exe", and
then programmatically set the linker's /OUT flag to OUTPUT_FILE.
MSDN directs me to import VCProjectEngine.dll, which has an
OutputFile.set() function, but I cannot find any example of this for
VC anywhere (the example they provide is in VB, which I am not fluent
in, and have not been able to translate to VC).
Their example:
Public Module Module1
Sub Test()
Dim prj As VCProject
Dim cfgs, tools As IVCCollection
Dim cfg As VCConfiguration
Dim tool As VCLinkerTool
prj = DTE.Solution.Projects.Item(1).Object
cfgs = prj.Configurations
cfg = cfgs.Item(1)
tool = cfg.Tools("VCLinkerTool")
tool.<b>OutputFile</b> = "$(ProjectName).x"
End Sub
End Module
I have tried instantiating a VCProject object, a VCLinkerTool object,
a VCConfiguration object, etc, to no avail ("cannot instantiate
abstract class due to following members: 'HRESULT
IUnknown::QueryInterface(const IID &_void **)' : is abstract")
Can anybody help me out? There has to be a simple way to set the
OutputFile programmatically.
Thank you for your time,
~Shane
ebs2002@gmail.com - 17 Apr 2007 15:16 GMT
Last night, I had been working on this problem for a few hours and my
brain was a little fried. I realize now the solution I was
investigating would be for setting the output file at run-time
(through instantiating a compiler and compiling a separate project, or
something along those lines).
My real question is, is there a way to programmatically set a flag pre-
compile that will change the /OUT flag the linker is using, ie through
a #pragma? An alternate approach: is there a way I can
programmatically set a compiler variable pre-compile that my project
can reference?
ie: my project settings have /OUT:${OutputFile}, and in my code I have
#pragma EnvironmentVariable OutputFile "outfile.exe"
Thank you for your time,
~Shane