Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » CDT building DLL for JNI with MinGW
CDT building DLL for JNI with MinGW [message #160347] Tue, 13 December 2005 06:25 Go to next message
Mike Greenawalt is currently offline Mike GreenawaltFriend
Messages: 50
Registered: July 2009
Member
I am using CDT with MinGW (v 4.1) for my build environment. I have written
my code to be buildable both as an EXE and as a DLL. In EXE form, I have
used the debugger successfully to work out the logic kinks.

Now it is time to build as a DLL and get the interfaces with JNI working.
Building the DLL works fine.

So far, it looks as though Java is loading the DLL alright, however I am
unable to link to any of the specified JNI entry points.

I am pretty sure I have all the naming conventions satisfied, and I am using
function prototypes as generated by javah.

MinGW has its own versions of headers and libraries for Windows system
functions. Is there any incompatibility with what Java expects in a JNI
application DLL? Has anyone else made a JNI dll using MinGW?

Thanks for any help.
-- Mike
Re: CDT building DLL for JNI with MinGW [message #160363 is a reply to message #160347] Tue, 13 December 2005 13:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jay.planettools.com

> So far, it looks as though Java is loading the DLL alright, however I am
> unable to link to any of the specified JNI entry points.

> I am pretty sure I have all the naming conventions satisfied, and I am using
> function prototypes as generated by javah.

> MinGW has its own versions of headers and libraries for Windows system
> functions. Is there any incompatibility with what Java expects in a JNI
> application DLL? Has anyone else made a JNI dll using MinGW?

Mike,

We are using the CDT and MinGW to compile and run DLL's currently. It
works fine, although required a significant amount of tweeking. As you
point out the naming conventions are tricky. Maybe you could send some
code snippets from the C side and the Java side on how they are called and
calling.

I am presently attempting to setup our DLL code to run as a stand-alone
exe (as you are already doing) and am having significant trouble with
that. It would seem that I need to get the jvm.lib to link in to the
project but I cannot figure out how to do that. I always tells me that it
cannot find the file. The help documentation is no help as it appears to
reference a completely different interface (one with a "External Library"
function). Although when I look at the linker command in the console it
appears correct, the "L" points to the directory and the "-l" option
points to the library. If you have any pointers for me on the method for
including the library so I can get access to the Java functions I would
certainly appreciate it.

Thanks,

Jay
Re: CDT building DLL for JNI with MinGW [message #160379 is a reply to message #160363] Tue, 13 December 2005 19:58 Go to previous messageGo to next message
Mike Greenawalt is currently offline Mike GreenawaltFriend
Messages: 50
Registered: July 2009
Member
I wonder what "tweeking" you had to do?

Your situation sounds different from mine. I am not trying to call Java
methods from C++, and I do not need the jvm.lib at all. My dll is actually
relatively simple -- it creates an invisible window and a message-handling
thread, and then simply marshals message strings between a Java application,
and a separate Windows application on the other side. I just have to get
strings out of the calling JVM and look up a methodId for a callback.

A colleague built my dll using M$ tools, and it worked without change. The
dll loads, and I can call the JNI methods in it. That means I had the naming
rigamarole right.

I wish I could be of more help.

-- Mike

"Jay Nance" <jay@planettools.com> wrote in message
news:2ad328921531095ba5950801d61f4cae$1@eclipse.org...
>> So far, it looks as though Java is loading the DLL alright, however I am
>> unable to link to any of the specified JNI entry points.
>
>> I am pretty sure I have all the naming conventions satisfied, and I am
>> using function prototypes as generated by javah.
>
>> MinGW has its own versions of headers and libraries for Windows system
>> functions. Is there any incompatibility with what Java expects in a JNI
>> application DLL? Has anyone else made a JNI dll using MinGW?
>
> Mike,
>
> We are using the CDT and MinGW to compile and run DLL's currently. It
> works fine, although required a significant amount of tweeking. As you
> point out the naming conventions are tricky. Maybe you could send some
> code snippets from the C side and the Java side on how they are called and
> calling.
>
> I am presently attempting to setup our DLL code to run as a stand-alone
> exe (as you are already doing) and am having significant trouble with
> that. It would seem that I need to get the jvm.lib to link in to the
> project but I cannot figure out how to do that. I always tells me that it
> cannot find the file. The help documentation is no help as it appears to
> reference a completely different interface (one with a "External Library"
> function). Although when I look at the linker command in the console it
> appears correct, the "L" points to the directory and the "-l" option
> points to the library. If you have any pointers for me on the method for
> including the library so I can get access to the Java functions I would
> certainly appreciate it.
>
> Thanks,
>
> Jay
>
>
>
Re: CDT building DLL for JNI with MinGW [message #160511 is a reply to message #160363] Thu, 15 December 2005 06:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: divis1969.mail.ru

Jay,

Dis you use exactly "jvm.lib" for the linker -j option?
If so, I think you could test the following: rename jvm.lib into libjvm.a
and use "jvm" for -l option (i.e. command line should look like
"gcc -L<your_dir> -ljvm .. ")

Probably it will cause some errors caused by unknown library format (since
it obviously was compiled by another compiler) but at least you will be sure
that linker has found this library. :-)

Dmitry

"Jay Nance" <jay@planettools.com> wrote in message
news:2ad328921531095ba5950801d61f4cae$1@eclipse.org...
>> So far, it looks as though Java is loading the DLL alright, however I am
>> unable to link to any of the specified JNI entry points.
>
>> I am pretty sure I have all the naming conventions satisfied, and I am
>> using function prototypes as generated by javah.
>
>> MinGW has its own versions of headers and libraries for Windows system
>> functions. Is there any incompatibility with what Java expects in a JNI
>> application DLL? Has anyone else made a JNI dll using MinGW?
>
> Mike,
>
> We are using the CDT and MinGW to compile and run DLL's currently. It
> works fine, although required a significant amount of tweeking. As you
> point out the naming conventions are tricky. Maybe you could send some
> code snippets from the C side and the Java side on how they are called and
> calling.
>
> I am presently attempting to setup our DLL code to run as a stand-alone
> exe (as you are already doing) and am having significant trouble with
> that. It would seem that I need to get the jvm.lib to link in to the
> project but I cannot figure out how to do that. I always tells me that it
> cannot find the file. The help documentation is no help as it appears to
> reference a completely different interface (one with a "External Library"
> function). Although when I look at the linker command in the console it
> appears correct, the "L" points to the directory and the "-l" option
> points to the library. If you have any pointers for me on the method for
> including the library so I can get access to the Java functions I would
> certainly appreciate it.
>
> Thanks,
>
> Jay
>
>
>
Re: CDT building DLL for JNI with MinGW [message #196211 is a reply to message #160379] Tue, 10 July 2007 22:41 Go to previous messageGo to next message
Cameron Taggart is currently offline Cameron TaggartFriend
Messages: 28
Registered: July 2009
Junior Member
I'm hoping to resurrect this thread from a while back. I'm using
Eclipse Europa with MinGW and I'm trying to build a ddl with JNI
methods. I have a trivial C function (from project GlueGen's example #1):

function.h
int one_plus(int a);

function.c
int one_plus(int a) {
return 1 + a;
}

I was able to compile the above into a dll with the native JNI code.
When I try to load and use the dll from Java, I get this error:
java.lang.UnsatisfiedLinkError: testfunction.TestFunction.one_plus(I)I

My guess is that it has something to do with how I built the dll, and
here is the MinGW FAQ entry regarding JNI:

http://www.mingw.org/mingwfaq.shtml#faq-jni-dll

I'm not sure how that translates into CDT managed build settings. I'm
guessing that I need to change stuff in MinGW C Linker > Shared Library
Settings.

Any ideas???

cheers,
Cameron


Mike Greenawalt wrote:
> I wonder what "tweeking" you had to do?
>
> Your situation sounds different from mine. I am not trying to call Java
> methods from C++, and I do not need the jvm.lib at all. My dll is actually
> relatively simple -- it creates an invisible window and a message-handling
> thread, and then simply marshals message strings between a Java application,
> and a separate Windows application on the other side. I just have to get
> strings out of the calling JVM and look up a methodId for a callback.
>
> A colleague built my dll using M$ tools, and it worked without change. The
> dll loads, and I can call the JNI methods in it. That means I had the naming
> rigamarole right.
>
> I wish I could be of more help.
>
> -- Mike
>
> "Jay Nance" <jay@planettools.com> wrote in message
> news:2ad328921531095ba5950801d61f4cae$1@eclipse.org...
>>> So far, it looks as though Java is loading the DLL alright, however I am
>>> unable to link to any of the specified JNI entry points.
>>> I am pretty sure I have all the naming conventions satisfied, and I am
>>> using function prototypes as generated by javah.
>>> MinGW has its own versions of headers and libraries for Windows system
>>> functions. Is there any incompatibility with what Java expects in a JNI
>>> application DLL? Has anyone else made a JNI dll using MinGW?
>> Mike,
>>
>> We are using the CDT and MinGW to compile and run DLL's currently. It
>> works fine, although required a significant amount of tweeking. As you
>> point out the naming conventions are tricky. Maybe you could send some
>> code snippets from the C side and the Java side on how they are called and
>> calling.
>>
>> I am presently attempting to setup our DLL code to run as a stand-alone
>> exe (as you are already doing) and am having significant trouble with
>> that. It would seem that I need to get the jvm.lib to link in to the
>> project but I cannot figure out how to do that. I always tells me that it
>> cannot find the file. The help documentation is no help as it appears to
>> reference a completely different interface (one with a "External Library"
>> function). Although when I look at the linker command in the console it
>> appears correct, the "L" points to the directory and the "-l" option
>> points to the library. If you have any pointers for me on the method for
>> including the library so I can get access to the Java functions I would
>> certainly appreciate it.
>>
>> Thanks,
>>
>> Jay
>>
>>
>>
>
>
Re: CDT building DLL for JNI with MinGW [message #196292 is a reply to message #196211] Wed, 11 July 2007 12:20 Go to previous messageGo to next message
Guenther Koegel is currently offline Guenther KoegelFriend
Messages: 56
Registered: July 2009
Member
Cameron Taggart wrote:
> I'm hoping to resurrect this thread from a while back. I'm using
> Eclipse Europa with MinGW and I'm trying to build a ddl with JNI
> methods. I have a trivial C function (from project GlueGen's example #1):
>
> function.h
> int one_plus(int a);
>
> function.c
> int one_plus(int a) {
> return 1 + a;
> }

Hi Cameron,

what does the command

javah testfunction.TestFunction

think how the function should be named? This command takes your class
and generates the header information for the native functions. It knows
about special characters (like your underscore) in the name. Use the
command from the same JDK you are using for running your application.

My guess is something like:

JNIEXPORT jint JNICALL Java_testfunction_TestFunction_one_plus(jint);

In this case, change the function signature and recompile. Then it
should work.

Bye

G&uuml;nther
Re: CDT building DLL for JNI with MinGW [message #196422 is a reply to message #196292] Wed, 11 July 2007 18:04 Go to previous message
Cameron Taggart is currently offline Cameron TaggartFriend
Messages: 28
Registered: July 2009
Junior Member
The solution was to tell the MinGW to remove the '@' symbol from
function names with the linker argument: -Wl,--kill-at

Project Properties > C/C++ Build > Settings > Tool Settings
> MinGW C Linker > Miscellaneous > Linker flags: -Wl,--kill-at

This MinGW FAQ entry almost makes it clear:
http://www.mingw.org/mingwfaq.shtml#faq-jni-dll

Cameron

Guenther Koegel wrote:
> Cameron Taggart wrote:
>> I'm hoping to resurrect this thread from a while back. I'm using
>> Eclipse Europa with MinGW and I'm trying to build a ddl with JNI
>> methods. I have a trivial C function (from project GlueGen's example
>> #1):
>>
>> function.h
>> int one_plus(int a);
>>
>> function.c
>> int one_plus(int a) {
>> return 1 + a;
>> }
>
> Hi Cameron,
>
> what does the command
>
> javah testfunction.TestFunction
>
> think how the function should be named? This command takes your class
> and generates the header information for the native functions. It knows
> about special characters (like your underscore) in the name. Use the
> command from the same JDK you are using for running your application.
>
> My guess is something like:
>
> JNIEXPORT jint JNICALL Java_testfunction_TestFunction_one_plus(jint);
>
> In this case, change the function signature and recompile. Then it
> should work.
>
> Bye
>
> G&uuml;nther
Previous Topic:Overriding default content types
Next Topic:Option which shows the indexer problems
Goto Forum:
  


Current Time: Mon May 06 23:05:46 GMT 2024

Powered by FUDForum. Page generated in 5.04739 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top