1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<chapter>
<title>Using libjclass in your application</title>
<para>
The easiest way to compile an application with libjclass is by using the
pkg-config utility. The following shell session shows how to compile
a hello program with pkg-config.
<example>
<title>Compile hello.c that uses libjclass</title>
<computeroutput>
cc `pkg-config --cflags --libs jclass` hello.c -o hello
</computeroutput>
</example>
</para>
<para>
If you don"t have pkg-config you can still use libjclass, but
you will need a little more effort.
<example>
<title>Compile hello.c that uses libjclass on MinGW</title>
jclassinfo is installed in jdir.
<computeroutput>
gcc -Ijdir/include -Ljdir/lib -lc -lm -lz -ljclass -o hello.exe hello.c
</computeroutput>
</example>
</para>
<para>
Here"s the source code for a sample hello.c.
</para>
<para>
It loads the HelloWorld class, gets its fully qualified name and prints it.
</para>
<para>
<programlisting>
<![CDATA[
#include <stdio.h>
#include <stdlib.h>
#include <jclass/jclass.h>
int main(int argc, char *argv[])
{
JavaClass *helloWorld;
helloWorld = jclass_class_new("HelloWorld", NULL, NULL);
if (helloWorld)
{
char *class_name;
class_name = jclass_class_get_class_name(helloWorld);
puts(class_name);
free(class_name);
jclass_class_free(helloWorld);
}
}
]]>
</programlisting>
</para>
</chapter>
|