开发者

Does g++ still generate an output file even if the program fails to compile/load?

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.


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
%


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).


g++ -o out.tmp `find ./ -iname "*.h" -or -iname "*.cpp"` && mv out.tmp out
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜