This discussion is archived
11 Replies Latest reply: May 22, 2012 5:56 AM by EJP RSS

creating dll for JNI?.

938414 Newbie
Currently Being Moderated
Hello!

I've completed two JNI examples in Linux Ubuntu 11.04:

1. http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html

2. http://csharp.com/javacfort.html

Now I'd like to prepare Windows versions of these examples. But I stuck on creating
dll recognized by Windows. I tried CygWin, minGW and Visual C++ 2010 Express.
But gcc (Cygwin and minGW) and cl (Visual) have problems with such task.
Particularly with lines:

#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>

Cannot find these headers. So my question is: how to create dll in such cases?. What tools should I
use, what commands should I issue?.
Or, perhaps, there are some other ways?. For example, running Linux versions in Windows?.
The biggest problem is this native library :(.

Cheers,

Mac.
  • 1. Re: creating dll for JNI?.
    EJP Guru
    Currently Being Moderated
    Those headers don't exist in Windows. The functions they define don't exist in Windows. You will have to adjust your C code so that it calls functions that do exist in Windows, and include the corresponding header files.

    None of this has anything to do with Java, or these forums, or this site.
  • 2. Re: creating dll for JNI?.
    938414 Newbie
    Currently Being Moderated
    I wouldn't agree. The first example is from Oracle Sun Tutorial about JNI. So this example is wrong? (at least for Windows?).

    Edited by: 935411 on 2012-05-19 04:32
  • 3. Re: creating dll for JNI?.
    EJP Guru
    Currently Being Moderated
    If it was correct it would compile. As it doesn't compile, it isn't correct. There is no mmap() function in Windows. There is a similar function with a different name, but that's not a Java question. None of it is.
  • 4. Re: creating dll for JNI?.
    938414 Newbie
    Currently Being Moderated
    Hmm, perhaps you're right. But I think this forum is attended by people who did such things. Because this is also a question of running java program. If I don't create proper dll, I won't run java program in windows either. So by using JNI in windows one has to learn how to create dll. If it's not the proper forum, perhaps, You could direct me to a proper one?.

    Edited by: 935411 on 2012-05-19 08:08
  • 5. Re: creating dll for JNI?.
    EJP Guru
    Currently Being Moderated
    The question of whether or not a Windows C SDK contains mmap.h and a linkable mmap() function has nothing to do with Java.

    Relevance of your post to Java starts when you define your Java native method and run javah, ceases while you write, compile, and link your C code, and starts again when you are in a position to execute it.
  • 6. Re: creating dll for JNI?.
    938414 Newbie
    Currently Being Moderated
    OK, let's tackle it from another angle :). I will not ask how to change C code. But I'd like to ask what are the options of adapting Fortran 77 program (code) to use it with Java (adding GUI). That's a general quesiton, right? :). One can intercept inputs and outputs of the program. But what if I have to pass arguments from Java program into Fortran function and get result of that function, again, in Java program. What are my options?.
  • 7. Re: creating dll for JNI?.
    EJP Guru
    Currently Being Moderated
    The question is so vague as to be unanswerable. All I can tell you is what JNI does. You define a native method in the Java syntax, so you are restricted to Java semantics as well: pass by value, Java datatypes, etc. You then generate a C header and stub file from that Java class. You then write the implementation(s) of the native method(s).

    Matching that up to what you have to interface to isn't a Java question either.
  • 8. Re: creating dll for JNI?.
    gimbal2 Guru
    Currently Being Moderated
    935411 wrote:
    OK, let's tackle it from another angle :). I will not ask how to change C code.
    Well welcome to the wonderful world of C/C++ programming!

    The answer to your question is: a few years of schooling, half a dozen years of programming experience, the reading of a huge pile of books on a wide variety of subjects and doing actual coding on a daily basis. That's how I did it anyway. I'm glad I had that learning experience, I'm also glad I don't have to deal with it anymore.
  • 9. Re: creating dll for JNI?.
    938414 Newbie
    Currently Being Moderated
    Well, but we can talk about it and discuss it, or, perhaps, this is forbidden on this forum :) ?. And, please, correct JNI example. It may confuse beginner. Thanks for answers. I got, what I wanted, working (finally, uff).

    Edited by: 935411 on 2012-05-22 05:25
  • 10. Re: creating dll for JNI?.
    gimbal2 Guru
    Currently Being Moderated
    935411 wrote:
    Well, but we can talk about it and discuss it, or, perhaps, this is forbidden on this forum :) ?
    Stack overflow is more suited for cross-language discussions, this is the Java discussion forum.
    . And, please, correct JNI example.
    You are mistaken. We're not Oracle employees.
    It may confuse beginner.
    Beginners have no business even touching JNI. People who don't know C/C++ or the environment their programming for don't have either. People who are not beginners and/or know C/C++ won't be confused.
  • 11. Re: creating dll for JNI?.
    EJP Guru
    Currently Being Moderated
    Well, but we can talk about it and discuss it, or, perhaps, this is forbidden on this forum :) ?
    How many times exactly do you have to be told that it's off topic?

    It is also quite pointless. It's a Java Programming forum. People here are experts in Java programming. Not the Windows API. You can see that for yourself by the responses you've had over the last four days. Persisting with that discussion in the face of basically zero response isn't a rational strategy. Surely this is obvious?
    And, please, correct JNI example.
    Submit a bug report. Again, this isn't the place to do that.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points