rng_58's blog

By rng_58, history, 6 years ago, In English

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
Tags gcj, dcj
  • Vote: I like it
  • +52
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it +49 Vote: I do not like it

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.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you! So, can we assume that "C++ 6.3.0" on Debian Linux means g++?

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I'm pretty sure that yes. It's by far the most common one.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    or use a single command: g++ A.cpp -O2 -o A && ./A < A.in | tee A.out

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +27 Vote: I do not like it

    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.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +7 Vote: I do not like it

      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?"

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        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?

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +17 Vote: I do not like it

    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

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    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.

»
6 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Does g++ on Cygwin compile + run?

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yeah, I was asking, because < A.in | tee A.out should be part of running, not compiling, right?

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes, that was a mistake, fixed it.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like 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.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Instead of ./a < A.in | tee A.out you can simply write ./a < A.in > A.out

  • »
    »
    6 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    ./a < A.in | tee A.out == ./a < A.in > A.out && cat A.out, it's not the same thing.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Actually two things you printed are also not same

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        How so?

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it
          Try this 4
          • »
            »
            »
            »
            »
            »
            6 years ago, # ^ |
            Rev. 2   Vote: I like it 0 Vote: I do not like it

            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.

            • »
              »
              »
              »
              »
              »
              »
              6 years ago, # ^ |
                Vote: I like it +13 Vote: I do not like it

              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.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

So actual software they have, I must say.

»
6 years ago, # |
  Vote: I like it +204 Vote: I do not like it

rm -rf *

  • »
    »
    6 years ago, # ^ |
      Vote: I like it -22 Vote: I do not like it

    LOL!! This wouldn't work tho without this badboy

    Spoiler
    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +2 Vote: I do not like it

      It's "remove everything from current directory".

»
6 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    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?