有关Node类的Solaris CC警告

时间:2013-02-11 07:22:35

标签: java c++ java-native-interface solaris-10

我们有一个带有名为Node的类的C ++应用程序,它使用Java Invocation API嵌入JVM。使用JDK 1.7,C ++代码的编译会发出警告

ld: warning: symbol 'Node::__vtbl' has differing sizes:
        (file /tools/java/java170_09/jre/lib/sparcv9/server/libjvm.so value=0xd0; file test.o value=0x20);
        test.o definition taken

我们的Node类具有虚函数,可能与JVM的Node类冲突。有人可以帮助摆脱警告(我们不想更改类名:-()

测试代码:

#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

void printHello();
void doSomething();
int main(){
    cout<<("Solaris JNI Experiment\n");



    //From http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html

    JavaVM *jvm;       /* denotes a Java VM */
    JNIEnv *env;       /* pointer to native method interface */

    JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */

    JavaVMOption* options = new JavaVMOption[2];    
    options[0].optionString = "-Djava.class.path=./jvmtest/classes";
    //this was suggested in one of the bugs of JDK 1.7. Would like to verify the effect of this with the crash.
    options[1].optionString = "-Djava.library.path=/tools/java/java170_09/jre/lib/sparcv9:/tools/java/java170_09/jre/lib/sparcv9/server:/usr/lib/sparcv9:./classes:.";

    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = false;


    if (JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args)) {
        #pragma convert(0)
        fprintf(stderr, "Failed to create the JVM\n");
        #pragma convert(819)
        exit(1);
    }       

    jclass cls = env->FindClass("testJNI2");
    jmethodID mid = env->GetStaticMethodID(cls, "sayHello", "(I)V");
    env->CallStaticVoidMethod(cls, mid, 10);

    printHello();



    jvm->DestroyJavaVM();


    return 0;
}



void doSomething(){
    int i=1, j=2;
    i= (i+j)/2;
    //cout<<("doSomething");
}

class Node {
  public:
    Node () :count(1) {}
    virtual ~Node () {}

    virtual void virtual_function () {
      count+= 10;
    }

    void non_virtual_function () {
      count+= 1;
    }

    int getCount() {
      return count;
    }

  private:
    int count;

};

Node node;

void printHello(){
    cout<<("hello\n");
    int i=0;
    for(i=0;i<50000;i++){
        doSomething();
    }
    Node *node_rptr = new Node();
    //node_rptr->non_virtual_function();
    node_rptr->virtual_function();

    cout << node_rptr->getCount();

    delete node_rptr;
}

0 个答案:

没有答案