Setup and Compilation for C, Java, and Ruby Programs

Setup and Compilation for C, Java, and Ruby Programs
Slide Note
Embed
Share

Learn how to set up and compile C, Java, and Ruby programs efficiently using gcc for C, javac for Java, and Ruby commands. The tutorial provides detailed instructions for installing necessary tools, creating source files, compiling code, and running programs from the terminal. Explore examples, makefile usage, and calling system commands within Java to enhance your programming experience.

  • Compilation
  • Programming
  • C
  • Java
  • Ruby

Uploaded on Feb 18, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Tutorial 6 Assignment 2

  2. If using C gcc is most likely installed by default. Otherwise, you need to install it Submit your source code file with extension .c (A2com.c) Create a file and name it makefile (no extension) and submit it as well Put the following two lines in it A2com : A2com.c gcc -o A2com A2com.c N.B. you must indent this line with tab

  3. If using C cont. To compile and run your code from your terminal, type: make chmod u+x A2com ./A2com

  4. If using C Running the ls -l command: system( ls -l );

  5. If using Java Install java Submit your source code file with extension .java (A2com.java) Create a file and name it makefile (no extension) and submit it as well Put the following two lines in it A2com.class: A2com.java javac A2com.java N.B. you must indent this line with tab

  6. If using Java cont. Create and submit a shell script called A2com with NO extension which calls java A2com To compile and run your code from your terminal, type: make chmod u+x A2com ./A2com

  7. If using Java cont. If you have more than one source file, the makefile can be done like A2com.class: A2com.java A2comextra.java javac A2com.java A2comextra.java N.B. you must indent this line with tab

  8. (ListOutput.java) program which demonstrates how to call the ls -l command from Java import java.io.*; public class ListOutput { public static void main(String[] args) throws IOException, InterruptedException { Runtime rt = Runtime.getRuntime(); Process p = rt.exec("ls -l"); p.waitFor(); BufferedReader lsOutput = new BufferedReader(new nputStreamReader(p.getInputStream())); String line; while ((line = lsOutput.readLine()) != null) { System.out.println(line); } } }

  9. If using Ruby Install Ruby Either you submit your Ruby solution (A2com) with NO .rb extension and with #!/usr/bin/env ruby) as the first line in your code Or you submit your Ruby solution (A2com.rb), and a shell script called A2com with NO .rb extension which calls ruby A2com.rb To compile and run your code: chmod u+x A2com ./A2com

  10. If using Python Install Python3. You might already have it. Either you submit your Python solution (A2com) with NO .py extension and with (#!/usr/bin/env python3) as the first line in your code Or you submit your Python solution (A2com.py), and a shell script called A2com with NO .py extension which calls python3 A2com.py To compile and run your code: chmod u+x A2com ./A2com

  11. If using Python Running the ls -l command: os.system( ls -l )

  12. If using Bash Most likely is installed by default Either you submit your Bash solution (A2com) with NO .sh extension and with #!/usr/bin/env bash) as the first line in your code Or you submit your Bash solution (A2com.sh), and a shell script called A2com with NO .sh extension which calls bash A2com.sh To compile and run your code: chmod u+x A2com ./A2com

  13. Testing Your work The program must accept commands typed at the terminal window It must also work correctly if the marker redirects input to the program from a file, e.g. make (if you have a makefile) chmod u+x A2com ./A2com< test1.txt ./A2com < test2.txt ./A2com < test3.txt ./A2com < test4.txt ./A2com < test5.txt ./A2com < test6.txt ./A2com < testspaces.txt

More Related Content