www.digitalmars.com         C & C++   DMDScript  

c++ - Errorlevel after linking failure?

reply SL <shadowlord13 gmail.com> writes:
I use batch files to compile and link things, and I have them pause only 
if there were errors (the window appears, compiles, and then closes if 
there are no errors). But I haven't been able to make it automatically 
pause if there's a linking error.

I noticed that dmc writes '--- errorlevel 1' if it fails to link 
something. However, when I checked the errorlevel in the batch file 
after calling dmc, it was 0, not 1.

Right now I'm assuming the errorlevel/return-value from the linker is 1, 
but dmc is still returning 0, so I should just have to separate the 
compiling and linking steps. I haven't tested this yet, though, and am 
wondering if this would be considered a bug.

P.S. Normally I detect compiling failure by checking if SyncStarmap.exe 
exists (The batch file deletes it before running dmc). If it exists, 
compilation was successful. However, the EXE is still written if linking 
fails. Windows knows it's invalid but I don't see any way to find out if 
it is from a batch file.
Mar 20 2005
parent Skylon <Skylon_member pathlink.com> writes:
In article <d1kikd$14m5$1 digitaldaemon.com>, SL says...
I use batch files to compile and link things, and I have them pause only 
if there were errors (the window appears, compiles, and then closes if 
there are no errors). But I haven't been able to make it automatically 
pause if there's a linking error.

I noticed that dmc writes '--- errorlevel 1' if it fails to link 
something. However, when I checked the errorlevel in the batch file 
after calling dmc, it was 0, not 1.

Right now I'm assuming the errorlevel/return-value from the linker is 1, 
but dmc is still returning 0, so I should just have to separate the 
compiling and linking steps. I haven't tested this yet, though, and am 
wondering if this would be considered a bug.

P.S. Normally I detect compiling failure by checking if SyncStarmap.exe 
exists (The batch file deletes it before running dmc). If it exists, 
compilation was successful. However, the EXE is still written if linking 
fails. Windows knows it's invalid but I don't see any way to find out if 
it is from a batch file.

Hmm, weird... dmc.exe and link.exe correctly return 1 when there is error occured on my machne. Well, here is is the answer for your second question: http://www.digitalmars.com/ctg/ctgLinkSwitches.html#delexecutable If you don't want to pass /DELEXECUTABLE to the the linker everytime you compile your program, look for 'sc.ini' under your 'bin' directory and add this line: OPTLINKS=/DELEXECUTABLE /ONERROR:NOEXE
Mar 21 2005