Re: Invoking gcj compile program from "c"

Vaijayanthi Mala Suresh <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
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 <[email protected]> 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.
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.