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
For C++, to obtain the same outcome:
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.Thank you! So, can we assume that "C++ 6.3.0" on Debian Linux means g++?
I'm pretty sure that yes. It's by far the most common one.
or use a single command:
g++ A.cpp -O2 -o A && ./A < A.in | tee A.out
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.
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?"
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?
Not sure, please ask codejam@google.com
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
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.
Does g++ on Cygwin compile + run?
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).
Yeah, I was asking, because
< A.in | tee A.out
should be part of running, not compiling, right?Yes, that was a mistake, fixed it.
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.
Instead of
./a < A.in | tee A.out
you can simply write./a < A.in > A.out
./a < A.in | tee A.out
==./a < A.in > A.out && cat A.out
, it's not the same thing.Actually two things you printed are also not same
How so?
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.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 withcat
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.So actual software they have, I must say.
rm -rf *
LOL!! This wouldn't work tho without this badboy
"sudo" xD
It's "remove everything from current directory".
I do not see any people mentioning the
--std=c++11
or--std=c++0x
or similar flags. You need these for range-basedfor
loops, which some of us like to use. :)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?For me it is two