I have a strange problem. I have a DUnit application, which I need to run as both GUI (on my development machine) and as a console app (on the build machine). I just copied the project file, renamed it. I have the usual :
I have a strange problem. I have a DUnit application, which I need to run as both GUI (on my development machine) and as a console app (on the build machine). I just copied the project file, renamed it. I have the usual :
{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}
And in one app I define the CONSOLE_TESTRUNNER conditional define and in the other I don't.
If I COMPILE the console application, it works as a console app. However, if I BUILD then it runs as a GUI app. I have even tried removing the conditional define and explicitly setting it as {$APPTYPE CONSOLE}, to remove the conditional define out of the equation, but then the application just throws out an EInOutError I/O error 105. I guess it's trying to write to the output but failing. But why?
{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}
And in one app I define the CONSOLE_TESTRUNNER conditional define and in the other I don't.
If I COMPILE the console application, it works as a console app. However, if I BUILD then it runs as a GUI app. I have even tried removing the conditional define and explicitly setting it as {$APPTYPE CONSOLE}, to remove the conditional define out of the equation, but then the application just throws out an EInOutError I/O error 105. I guess it's trying to write to the output but failing. But why?
What do you have under Project > Options > Delphi Compiler > Linking > Generate console application ?? Is that checked or not?
ReplyDeleteIt was not checked. However if I check it, it makes no difference. If I compile I get a console app, if I build I get a gui app.
ReplyDeleteDid you check what kind of build you're doing. If you specified CONSOLE_TESTRUNNER in the DEBUG-build, it might not be defined for the RELEASE-build (or visa versa).
ReplyDeleteYeah checked as well. I also tried eliminating the define by explicitly setting APPTYPE. If I build it is not a console app. If I compile it is.
ReplyDeleteHow do you build and how do you compile.
ReplyDeleteDelphi Berlin btw.
ReplyDeleteI can build and compile from the IDE or using MSBuild. Same result!
ReplyDeleteBuild and compile from the IDE should have the same result. Building outside the IDE with MSBuild could have different results. If you have different results with the build and compile in the IDE itself you might want to create a small test-project just to see if that works fine.
ReplyDeleteprogram test_project;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
begin
try
writeln('works');
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
/sub
ReplyDeleteProbably wrong, but clean up all build artifacts (.dcu's etc) everywhere. Aside, we have our testsuite always build as a GUI app. It has been slightly tailored to recognize a command line switch such that it (nevertheless) produces output to an NUnit compatible output for reporting by the build CI server (Jenkins).
ReplyDeleteI do have some vcl units in the project due to some old dependencies..
ReplyDelete