tags:

views:

64

answers:

3

I am compiling some C++ programs through a perl script using:

g++ -o out `find ./ -iname "*.h" -or -iname "*.cpp"`

This seems to generate an an out file every time, regardless of whether the program compiled successfully or not.
Whenever the script tries to run programs like this, it gets permission errors (weird since I'm running as root).
Is this accurate and if so, how can I prevent it?

Thanks.

A: 
g++ -o out.tmp `find ./ -iname "*.h" -or -iname "*.cpp"` && mv out.tmp out
Zan Lynx
+3  A: 

The answer to your title's question ("Does g++ still generate an output file even if the program fails to compile/load?") is no:

% echo blah > test.cpp
% g++ -o out test.cpp
test.cpp:1: error: expected constructor, destructor, or type conversion at end of input
% ls *out*
/bin/ls: *out*: No such file or directory
%
CanSpice
+1  A: 

I solved it as follows:
For some reason, trying to put the output executable using -o out seemed to force creating the file even after the compile failed (it seems to me).

chustar