What is the best way to pass information from java to c++?

后端 未结 8 1758
太阳男子
太阳男子 2021-02-07 04:59

I have a java application I need to pass some info to a C++ program. It has been suggested that I use some simple socket programming to do this. Is this the best way? If not

相关标签:
8条回答
  • 2021-02-07 05:33

    You could use the Java Native Interface (JNI). The JNI allows you to make calls to C libraries from Java applications. Note that JNI calls are C and not C++ calls so you will have to specify the C calling convention on your C++ functions (extern "C").

    JNI has a reputation of being hard to do. It's not easy but it's certainly doable. I would advice against using sockets. Using sockets sounds like the easy way out but to me it is tantamount to opening a can of nasty worms...

    0 讨论(0)
  • 2021-02-07 05:33

    Also, if this isn't lost in the noise, use SWIG to help you if you try the JNI route. http://www.swig.org/

    0 讨论(0)
提交回复
热议问题