How to change default output file of g++ in ubuntu?
43,167
Solution 1
You need to use the -o
option of g++
g++ -o output_file_name source.cpp
Solution 2
Use the g++
-o switch: g++ sample.cc -o myoutfile
See a man page for g++
-o file
Place output in file file.
Solution 3
If you want to change the default output name to test
for example, all you need to do is go to .bashrc, and put in:
alias g++='g++ -o test'
But you need to reopen a new terminal for it to work.
Solution 4
Man pages are your friends:
$ man g++
(and just do a search for "out" and you're done ;)
Author by
Nullpoet
Updated on June 30, 2020Comments
-
Nullpoet almost 4 years
Trivially
g++ sample.c
generates
a.out
Can g++ be configured to output to a different default name for output file ?
-
Martin York almost 14 yearsAll Unix like systems have what is called manual pages. You can read them by typing
man <command>
in this caseman g++
. Some modern versions also have the slightly more complex but also more complete information systems typesinfo <command>
orinfo g++
-
jedesah over 10 yearsI think the question here is asking if it's possible to change the default name not change the name on a case by case basis. So if I understand the question correctly, all of the answers below are incorrect. I actually came here looking for a way to change the default name, I know full well how the -o switch works as I suspect @Nullpoet does as well.
-
-
Username Obfuscation almost 6 yearsI think the pertinent word in the asker's question was 'default', i.e. where is it actually defined that a.out is the default setting when -o is not used, and how can you redefine a new default?