### rng_58's blog

By rng_58, history, 3 years ago,

I'm preparing for upcoming GCJ Finals. This year GCJ supports only Linux, and I want to learn how to compile solutions on Linux (I think I used it 9 years ago in IOI but completely forgot how to do that...).

Suppose that A.cpp, Main.java, A.py are source codes, A.in is the input, and you want to output to A.out.

On Windows+Cygwin, I usually do the following:

• g++ -Wl,--stack,268435456 A.cpp -O2
• ./a < A.in | tee A.out
• javac Main.java
• java Main < A.in | tee A.out
• python A.py

What commands do the same things on Linux?

The following things are installed on the machine:

• Debian Linux 9.4
• C++ 6.3.0
• Java 7 2.2.5
• Python 2 2.7.13

• +52

 » 3 years ago, # |   +49 For C++, to obtain the same outcome: ulimit -s 268435456 g++ A.cpp -O2 -o A ./A < A.in | tee A.out It may be possible to restrict stack size per app, but I couldn't find how. I'm suggesting ulimit, it sets stack size per bash session, I hope it's similar enough. I believe the other commands will be exactly the same as your Cygwin ones.
•  » » 3 years ago, # ^ |   0 Thank you! So, can we assume that "C++ 6.3.0" on Debian Linux means g++?
•  » » » 3 years ago, # ^ |   0 I'm pretty sure that yes. It's by far the most common one.
•  » » 3 years ago, # ^ |   0 or use a single command: g++ A.cpp -O2 -o A && ./A < A.in | tee A.out
•  » » 3 years ago, # ^ |   +27 I think that changing local stack size is a dangerous thing to do unless organizers confirmed that it would be the same on the testing system.
•  » » » 3 years ago, # ^ |   +7 Right, this is a very good point.You can find the judging system command lines at https://code.google.com/codejam/resources/faq , "For each language, what version, libraries, and compilation and execution lines does the platform use?"
•  » » » » 3 years ago, # ^ |   +1 Now I remember that this year we don't need to generate outputs locally :)Can we assume that the contestants' machine and the judge machine have similar performance?
•  » » » » » 3 years ago, # ^ |   +1 Not sure, please ask codejam@google.com
•  » » 3 years ago, # ^ |   +17 For those who didn't know (like me 5 minutes ago): tee writes to a file and to stdout. And it's named like that because that command has the same effect as a T junction. :-D
•  » » 3 years ago, # ^ |   +16 Whenever tee is used, I would recommend using it with |&, not just |. It captures stderr as well. If some error occurs and it is not directed to resulting log, this can be very confusing later.
 » 3 years ago, # |   +6 Does g++ on Cygwin compile + run?
•  » » 3 years ago, # ^ |   0 It just compiles. To run the program "./a" works. (I believe at least one of "./a", "./a.exe", or "./a.out" should work on Linux).
•  » » » 3 years ago, # ^ |   0 Yeah, I was asking, because < A.in | tee A.out should be part of running, not compiling, right?
•  » » » » 3 years ago, # ^ |   0 Yes, that was a mistake, fixed it.
•  » » » 3 years ago, # ^ |   0 a.out is the default output executable if you don't specify it with -o, otherwise the filename is the exact string you passed with -o, no extra extensions (Linux doesn't use .exe, but you can give it whatever extension you want)Cygwin shell is almost identical to Linux shell, so you shouldn't have much trouble.
 » 3 years ago, # |   0 Instead of ./a < A.in | tee A.out you can simply write ./a < A.in > A.out
•  » » 3 years ago, # ^ | ← Rev. 2 →   0 ./a < A.in | tee A.out == ./a < A.in > A.out && cat A.out, it's not the same thing.
•  » » » 3 years ago, # ^ |   0 Actually two things you printed are also not same
•  » » » » 3 years ago, # ^ |   0 How so?
•  » » » » » 3 years ago, # ^ |   0 Try this 4echo 'import sys\nprint(1);sys.exit(1)' | python3 | tee a.out echo 'import sys\nprint(1);sys.exit(1)' | python3 > a.out && cat a.out yes > a.out && cat a.out yes | tee a.out 
•  » » » » » » 3 years ago, # ^ | ← Rev. 2 →   0 But for problems where the input is just a file, isn't it the same thing? (assuming the file isn't a FIFO special file) Also, you can replace && by ; in the first example.
•  » » » » » » » 3 years ago, # ^ |   +13 If your program crashes on the input file, it also won't show the output. ; is better.Although my main issue is that if your program runs for significant amount of time, with tee you will see the output on the run, while with cat only after everything finishes. In the case of GCJ problems, this may mean you notice in time that there is something wrong with your output and have enough time to fix it.
 » 3 years ago, # |   0 So actual software they have, I must say.
 » 3 years ago, # |   +204 rm -rf *
•  » » 3 years ago, # ^ |   -22 LOL!! This wouldn't work tho without this badboy Spoiler"sudo" xD
•  » » » 3 years ago, # ^ |   +2 It's "remove everything from current directory".
 » 3 years ago, # | ← Rev. 2 →   0 I do not see any people mentioning the --std=c++11 or --std=c++0x or similar flags. You need these for range-based for loops, which some of us like to use. :)
•  » » 3 years ago, # ^ |   +5 Minor note, it's just a single dash in the flag on my g++ on macOS (-std=c++11). I thought Linux also only uses one dash?
•  » » » 3 years ago, # ^ |   0 For me it is two
 » 3 years ago, # | ← Rev. 2 →   -12 Command for Linux.1.Taking input from file but writing in terminal. g++ -std=c++11 filename.cpp ./a.out < inputfilename.txt 2.Taking input from file and writing in file. g++ -std=c++11 filename.cpp ./a.out < inputfilename.txt > outputfilename.txt