The objective of this lab is to access a library we created locally called myclibrary. The coding excercises will all be inside the file TestMyCLibrary.java
Note: Please don't be alarmed by the number of files that you see in the directory. Many of these files are there for your reference when working on the lab examples. All coding exercises exist in TestMyCLibrary.java.
The myclibrary
can be created if you have gcc compiler setup.
After learning about C Pointers, Structs and Array of Structs you will be making calls to the library based on your knowledge so far.
myclibrary.h
- The header file containing the functions you will be calling.display(struct person p)
displayAll(struct person *ptrArray, int size)
addNumbers(int a, int b, int *c)
struct person
- myclibrary.c - The implementation of the functions above
Assuming you are in the lab 3 directory Before you begin change directory to lab3 and run the following scripts to clean up:
Linux and MacOS
bash clean.sh
Windows
clean_windows.cmd
Assuming you have your JAVA_HOME and gcc compiler installed, you may run the commands below:
Linux
bash compile_myclibrary.c_linux.sh
bash jextract_linux.sh
After compiling a library file is created named: libmyclibrary.so
MacOS
bash compile_myclibrary.c_macos.sh
bash jextract_macos.sh
After compiling a library file is created named: libmyclibrary.dylib
Windows
cd lab3
clean.cmd
compile_myclibrary.c_windows.cmd
bash jextract_windows.cmd
After compiling a library file is created named: myclibrary.dll
Above, you changed directory to lab3, cleaned up old files, compile and build custom library, and run jextract to generate classes and source code.
Linux or MacOS
run_TestMyCLibrary.sh
Windows
run_TestMyCLibrary_windows.cmd
The following are the exercises for Lab 3:
void addNumbers(int a, int b, int *c)
Expected output:
Java 5 + 10 = 15
void display(struct person p);
Expected output:
Name: Dr X
Age: 230
void displayAll(struct person *ptrArray, int size);
The objective is to create an array of structs to be passed to displayAll with the size of the array.
- Expected output:
Name: Person 0
Age: 100
Name: Person 1
Age: 101