This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: calling java from c++


akos.szalay@sophos.com wrote:

>I'm trying to call java from c++ using gcj.
>I thought, that the following code should work, but it coredumps
>(segmentation fault) on new.
>Any idea what's wrong with it ? (any workaround for this problem ?)
>I'm running redhat linux 7.1
>

You must call JvCreateJavaVM() before making any calls to Java code from 
an application with a C/C++ "main" method. eg:


--- orig/javatest.cpp   Thu Mar 28 11:28:23 2002
+++ javatest.cpp        Thu Mar 28 11:26:26 2002
@@ -7,6 +7,7 @@
 {
   printf("Starting...\n");
 
+  JvCreateJavaVM(NULL);
   otherclass *ttt = new otherclass();
 
   printf("Otherclass created (%p)\n",ttt);


Note that this only works with GCJ 3.1 and up.

regards

Bryce.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]