3
1
SystemsProgrammingAndOperat.../Codes/Group A/Assignment-A3
2024-11-06 02:36:27 +05:30
..
A3.c Added A3 code and updated link in README. 2024-10-14 23:12:47 +05:30
A3.java Added A3 code and updated link in README. 2024-10-14 23:12:47 +05:30
EXPLANATION.md Added explanation for A3 (dll) code. 2024-11-06 02:36:27 +05:30
README.md Added explanation for A3 (dll) code. 2024-11-06 02:36:27 +05:30

Steps to run this code

These are the steps to run code for Assignment-A3.


Refer EXPLANATION to understand how everything works.

Important

Tested on Linux and Windows.

Prerequisites

  1. open-jdk (version 11 or higher)
  2. gcc
  3. Set open-jdk and gcc as environment variables using bin folder in path (For Windows Users only)
  4. Common sense

Steps For Linux

  1. Compile A3.java:
javac A3.java
  1. Generate header file:
javac -h . A3.java
  1. Compile C code:
gcc -shared -o libA3.so -fPIC -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" A3.c

Note

If you get an error saying "fatal error: jni.h: No such file or directory", this might be because you haven't set $JAVA_HOME environment variable. Usually JVM stuff is in /usr/lib/jvm/java-<version>-openjdk-amd64. To set JAVA_HOME environment variable, run: export $JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 (for version 17, adjust for your version accordingly.)

  1. Run program:
java -Djava.library.path=. A3

Steps For Windows

  1. Compile A3.java:
javac A3.java
  1. Generate header file:
javac -h . A3.java
  1. Set JAVA_HOME to the path of your jdk file location:

Note that this is my file location for jdk. It may differ for you.

set JAVA_HOME=C:\Program Files\openjdk-23.0.1_windows-x64_bin\jdk-23.0.1
  1. Compile C code:
gcc -shared -o A3.dll -fPIC -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" A3.c
  1. Run program:
java -Djava.library.path=. A3