I've been told by my teacher that my homework (a simple program, I chose to code in C++) must be runnable in Linux. Here's what he said exactly:
"...you should also include a README file that contains all command lines that should run by cut-and-paste. If you used C, then
$ gcc –o 2010-11649-hairpin 2010-11649-hairpin.c
$ 2010-11649-hairpin –input filename –l 200 –m 4 –h 20
"
Where -l 200, -m 4 and the like are parameters of the program.
I've always coded in Windows, and I have very little experience running programs from the command line, so I'm not sure what I need to do to make sure my program can run in Linux. Can someone help me figure out what I need to do? I've written the program, I just need to make sure everything works when the TA tries to run it in Linux.
First of all you will have to try this by executing your instructions on Linux.
If you have written your program in standard C/C++ it will compile and then run on Linux just fine. Once you get to the less basic parts, you have big chances you have used OS specific headers and it might not work as easily.
When compiling a C++ program under Linux, normally you want to use g++ the C++ compiler in gcc. Depending on your program, replacing gcc with g++ in your example might work (although your filenames probably are different).
So you might end up with something like:
g++ –o myprogram myprogram.cpp
./myprogram –l 200 –m 4
The above will only work for basic programs with all source code in a single directory.
One fast way to see that your program compiles in gcc is to use an online compiler like ideone. Paste you code there and select C++ 4.9.whateverversion (gcc) and then compile and run.
The alternative is to install a linux OS, easiest and most convenient way in a virtual machine. You can use the free oracle virtualbox or VMWare.
Setting up linux in a vm is easy
There are other answers here showing you how to compile your program from command line in linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With