2024-10-14 12:11:16 +05:30
|
|
|
## Steps to run this code
|
|
|
|
|
|
|
|
These are the steps to run code for Assignment-A3.
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
> [!IMPORTANT]
|
2024-11-04 19:23:20 +05:30
|
|
|
> Tested on Linux and Windows.
|
2024-10-14 12:11:16 +05:30
|
|
|
|
|
|
|
### Prerequisites
|
|
|
|
|
|
|
|
1. open-jdk (version 11 or higher)
|
|
|
|
2. gcc
|
2024-11-04 19:23:20 +05:30
|
|
|
3. Set open-jdk and gcc as environment variables using bin folder in path (For Windows Users only)
|
|
|
|
4. Common sense
|
2024-10-14 12:11:16 +05:30
|
|
|
|
2024-11-04 19:23:20 +05:30
|
|
|
### Steps For Linux
|
2024-10-14 12:11:16 +05:30
|
|
|
|
|
|
|
1. Compile `A3.java`:
|
|
|
|
```shell
|
|
|
|
javac A3.java
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Generate header file:
|
|
|
|
```shell
|
|
|
|
javac -h . A3.java
|
|
|
|
```
|
|
|
|
|
|
|
|
3. Compile C code:
|
|
|
|
```shell
|
|
|
|
gcc -shared -o libA3.so -fPIC -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" A3.c
|
|
|
|
```
|
|
|
|
|
|
|
|
4. Run program:
|
|
|
|
```shell
|
|
|
|
java -Djava.library.path=. A3
|
|
|
|
```
|
2024-11-04 19:23:20 +05:30
|
|
|
### Steps For Windows
|
|
|
|
|
|
|
|
1. Compile `A3.java`:
|
|
|
|
```shell
|
|
|
|
javac A3.java
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Generate header file:
|
|
|
|
```shell
|
|
|
|
javac -h . A3.java
|
|
|
|
```
|
|
|
|
|
|
|
|
3. 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.
|
|
|
|
```shell
|
|
|
|
set JAVA_HOME=C:\Program Files\openjdk-23.0.1_windows-x64_bin\jdk-23.0.1
|
|
|
|
```
|
|
|
|
|
|
|
|
4. Compile C code:
|
|
|
|
```shell
|
|
|
|
gcc -shared -o A3.dll -fPIC -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" A3.c
|
|
|
|
```
|
|
|
|
|
|
|
|
5. Run program:
|
|
|
|
```shell
|
|
|
|
java -Djava.library.path=. A3
|
|
|
|
```
|