* Invoking gcj compile program from "c"
@ 2009-05-27 7:29 Vaijayanthi Mala Suresh
2009-05-27 7:56 ` Andrew Haley
0 siblings, 1 reply; 6+ messages in thread
From: Vaijayanthi Mala Suresh @ 2009-05-27 7:29 UTC (permalink / raw)
To: java
I have written an HelloWorld.java as given below
public class HelloWorld {
public HelloWorld()
{
System.out.println("Hello from constructor");
}
public void printline()
{
System.out.println("Hello from printline");
}
public static void main(String [] args) {
System.out.println("Hello from main");
HelloWorld ht = new HelloWorld();
ht.printline();
}
}
I have compiled it with gcj as given belwo
gcj -c HelloWorld.java
gcj -shared HelloWorld.o -o libHelloWorld.so
Copied the .so file into the folder as per LD_LIBRARY_PATH.
I have a cstartup.c which does the JVM Initialization and has to do a
FindClass() as given below
res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
if (res < 0)
{
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
cls = (*env)->FindClass(env, "HelloWorld");
if (cls == 0)
{
fprintf(stderr, "Can't find HelloWorld class\n");
exit(1);
}
This prints me "Can't find HelloWorld class"
Can someone help me in this regard?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Invoking gcj compile program from "c"
2009-05-27 7:29 Invoking gcj compile program from "c" Vaijayanthi Mala Suresh
@ 2009-05-27 7:56 ` Andrew Haley
2009-05-27 8:26 ` Vaijayanthi Mala Suresh
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2009-05-27 7:56 UTC (permalink / raw)
To: Vaijayanthi Mala Suresh; +Cc: java
Vaijayanthi Mala Suresh wrote:
> I have written an HelloWorld.java as given below
>
> public class HelloWorld {
> public HelloWorld()
> {
> System.out.println("Hello from constructor");
> }
> public void printline()
> {
> System.out.println("Hello from printline");
> }
> public static void main(String [] args) {
> System.out.println("Hello from main");
> HelloWorld ht = new HelloWorld();
> ht.printline();
> }
> }
>
> I have compiled it with gcj as given belwo
> gcj -c HelloWorld.java
> gcj -shared HelloWorld.o -o libHelloWorld.so
>
> Copied the .so file into the folder as per LD_LIBRARY_PATH.
>
> I have a cstartup.c which does the JVM Initialization and has to do a
> FindClass() as given below
>
> res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
> if (res < 0)
> {
> fprintf(stderr, "Can't create Java VM\n");
> exit(1);
> }
>
>
> cls = (*env)->FindClass(env, "HelloWorld");
> if (cls == 0)
> {
> fprintf(stderr, "Can't find HelloWorld class\n");
> exit(1);
> }
>
> This prints me "Can't find HelloWorld class"
>
> Can someone help me in this regard?
I'm guessing you haven't linked everything correctly. However, you haven't
shown us how cstartup.c is linked against libHelloWorld.so, so it's hard to
say. Please give a *complete* test case, with all code and all the
commands you used to build it.
Andrew.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Invoking gcj compile program from "c"
2009-05-27 7:56 ` Andrew Haley
@ 2009-05-27 8:26 ` Vaijayanthi Mala Suresh
2009-05-27 8:36 ` Andrew Haley
0 siblings, 1 reply; 6+ messages in thread
From: Vaijayanthi Mala Suresh @ 2009-05-27 8:26 UTC (permalink / raw)
To: Andrew Haley; +Cc: java
Hi Andrew,
I didn't do any linking explicitly. I was assuming that if the
library is placed under /lib folder it will get loaded automatically.
Later I tried the following before invoking the FindClass()
void *h = dlopen("/lib/libHelloWorld.so", RTLD_LAZY);
if (h == NULL)
{
const char *msg = dlerror();
printf("VMJ Error %s\n",msg);
}
It returns me an error "File Not Found"
Thanks
Mala
On Wed, May 27, 2009 at 1:26 PM, Andrew Haley <aph@redhat.com> wrote:
> Vaijayanthi Mala Suresh wrote:
>> I have written an HelloWorld.java as given below
>>
>> public class HelloWorld {
>> public HelloWorld()
>> {
>> System.out.println("Hello from constructor");
>> }
>> public void printline()
>> {
>> System.out.println("Hello from printline");
>> }
>> public static void main(String [] args) {
>> System.out.println("Hello from main");
>> HelloWorld ht = new HelloWorld();
>> ht.printline();
>> }
>> }
>>
>> I have compiled it with gcj as given belwo
>> gcj -c HelloWorld.java
>> gcj -shared HelloWorld.o -o libHelloWorld.so
>>
>> Copied the .so file into the folder as per LD_LIBRARY_PATH.
>>
>> I have a cstartup.c which does the JVM Initialization and has to do a
>> FindClass() as given below
>>
>> res = JNI_CreateJavaVM(&jvm,&env,&vm_args);
>> if (res < 0)
>> {
>> fprintf(stderr, "Can't create Java VM\n");
>> exit(1);
>> }
>>
>>
>> cls = (*env)->FindClass(env, "HelloWorld");
>> if (cls == 0)
>> {
>> fprintf(stderr, "Can't find HelloWorld class\n");
>> exit(1);
>> }
>>
>> This prints me "Can't find HelloWorld class"
>>
>> Can someone help me in this regard?
>
> I'm guessing you haven't linked everything correctly. However, you haven't
> shown us how cstartup.c is linked against libHelloWorld.so, so it's hard to
> say. Please give a *complete* test case, with all code and all the
> commands you used to build it.
>
> Andrew.
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Invoking gcj compile program from "c"
2009-05-27 8:26 ` Vaijayanthi Mala Suresh
@ 2009-05-27 8:36 ` Andrew Haley
2009-05-27 8:54 ` Vaijayanthi Mala Suresh
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2009-05-27 8:36 UTC (permalink / raw)
To: Vaijayanthi Mala Suresh; +Cc: java
Vaijayanthi Mala Suresh wrote:
> I didn't do any linking explicitly. I was assuming that if the
> library is placed under /lib folder it will get loaded automatically.
Not by default. I guess you were trying to use the
`gnu.gcj.runtime.VMClassLoader.library_control' property.
> Later I tried the following before invoking the FindClass()
>
> void *h = dlopen("/lib/libHelloWorld.so", RTLD_LAZY);
> if (h == NULL)
> {
> const char *msg = dlerror();
> printf("VMJ Error %s\n",msg);
> }
>
> It returns me an error "File Not Found"
That should work a lot better, but I'm not sure why a "File Not Found"
happens. I'd try using "strace -f -etrace=file" to see exactly which
file isn't being found.
Andrew.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Invoking gcj compile program from "c"
2009-05-27 8:36 ` Andrew Haley
@ 2009-05-27 8:54 ` Vaijayanthi Mala Suresh
2009-05-27 8:56 ` Andrew Haley
0 siblings, 1 reply; 6+ messages in thread
From: Vaijayanthi Mala Suresh @ 2009-05-27 8:54 UTC (permalink / raw)
To: Andrew Haley; +Cc: java
Hi Andrew,
Sorry...I didn't get you.
Do you mean to use this common @ the prompt as given below
strace -f -etrace=libHelloWorldImp.so
If yes, then I am getting the following error
strace: invalid system call `/libHelloWorldImp.so'
Thanks
Mala
On Wed, May 27, 2009 at 2:05 PM, Andrew Haley <aph@redhat.com> wrote:
> Vaijayanthi Mala Suresh wrote:
>
>> I didn't do any linking explicitly. I was assuming that if the
>> library is placed under /lib folder it will get loaded automatically.
>
> Not by default. I guess you were trying to use the
> `gnu.gcj.runtime.VMClassLoader.library_control' property.
>
>> Later I tried the following before invoking the FindClass()
>>
>> void *h = dlopen("/lib/libHelloWorld.so", RTLD_LAZY);
>> if (h == NULL)
>> {
>> const char *msg = dlerror();
>> printf("VMJ Error %s\n",msg);
>> }
>>
>> It returns me an error "File Not Found"
>
> That should work a lot better, but I'm not sure why a "File Not Found"
> happens. I'd try using "strace -f -etrace=file" to see exactly which
> file isn't being found.
>
> Andrew.
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Invoking gcj compile program from "c"
2009-05-27 8:54 ` Vaijayanthi Mala Suresh
@ 2009-05-27 8:56 ` Andrew Haley
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2009-05-27 8:56 UTC (permalink / raw)
To: Vaijayanthi Mala Suresh; +Cc: java
Vaijayanthi Mala Suresh wrote:
> Sorry...I didn't get you.
>
> Do you mean to use this common @ the prompt as given below
>
> strace -f -etrace=libHelloWorldImp.so
You really should read the strace man page first, but
strace -f -etrace=file <your command>
Andrew.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-05-27 8:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-27 7:29 Invoking gcj compile program from "c" Vaijayanthi Mala Suresh
2009-05-27 7:56 ` Andrew Haley
2009-05-27 8:26 ` Vaijayanthi Mala Suresh
2009-05-27 8:36 ` Andrew Haley
2009-05-27 8:54 ` Vaijayanthi Mala Suresh
2009-05-27 8:56 ` Andrew Haley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).