Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JNI: Does anybody use G++ on Windows (mingw32) to make DLLs?

1 view
Skip to first unread message

Francesco Moi

unread,
Apr 10, 2002, 4:42:34 AM4/10/02
to
Hello.

I'm trying to create a DLL:

--------------/HelloWorld.cpp/------
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>

JNIEXPORT void JNICALL
Java_HelloWorld_displayMessage(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
-----------------//-------------------

But I do not have any idea in order to compile this CPP with g++. Wich is the way?

(I've got already created the Java classes and the C++ header file)

Thank you very much.

Gordon Beaton

unread,
Apr 10, 2002, 5:13:54 AM4/10/02
to

Your example is C, not C++, so why not use gcc instead of g++?

At any rate, did you look at the dll documentation and examples on the
cygwin site?

http://cygwin.com/docs.html
http://cygwin.com/faq/faq_4.html#SEC107
http://cygwin.com/faq/faq_4.html#SEC109

/gordon

--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m

Jim Sculley

unread,
Apr 10, 2002, 7:33:00 AM4/10/02
to

As Gordon said, use GCC. A typical command might look like this:

gcc -shared -o hello.dll (path to JNI headers) HelloWorld.cpp -Wl,--kill-at

The item (path to JNI headers) is something like

-ID:/j2sdk1.4.0/include -ID:/j2sdk1.4.0/include/win32


Francesco Moi

unread,
Apr 10, 2002, 10:30:58 AM4/10/02
to
Thank you, Gordon.

I do really want to use C++, not C. I know that the sent code is C,
but it was due to the test I was making.

I'm trying with:

#include <iostream.h>
#include "HelloWorld.h" // this header file was generated by javah
using namespace std;

JNIEXPORT void JNICALL Java_HelloWorld_displayMessage(JNIEnv *env,
jobject obj)
{

cout << "Hello World! ";
}

I tried with:
c:> g++ -I"D:\j2sdk\include" -I"D:\j2sdk\include\win32" HelloWorld.cpp
-shared -o HelloWorldImp.dll

But I get this error message when calling from 'Main.java':
Exception in thread "main" java.lang.UnsatisfiedLinkError:
displayMessage
at HelloWorld.displayMessage(Native Method)
at Main.main(Main.java:6)

Thank you.

Gordon Beaton <n...@for.email> wrote in message news:<a90voi$or9$1...@news.du.uab.ericsson.se>...

Gordon Beaton

unread,
Apr 10, 2002, 10:56:57 AM4/10/02
to
On 10 Apr 2002 07:30:58 -0700, Francesco Moi wrote:
> Thank you, Gordon.
>
> I do really want to use C++, not C. I know that the sent code is C,
> but it was due to the test I was making.
>
> I'm trying with:
>
> #include <iostream.h>
> #include "HelloWorld.h" // this header file was generated by javah
> using namespace std;
>
> JNIEXPORT void JNICALL Java_HelloWorld_displayMessage(JNIEnv *env,
> jobject obj)
> {
> cout << "Hello World! ";
> }
>
> I tried with:
> c:> g++ -I"D:\j2sdk\include" -I"D:\j2sdk\include\win32" HelloWorld.cpp
> -shared -o HelloWorldImp.dll
>
> But I get this error message when calling from 'Main.java':
> Exception in thread "main" java.lang.UnsatisfiedLinkError:
> displayMessage
> at HelloWorld.displayMessage(Native Method)
> at Main.main(Main.java:6)

I have already answered this in comp.lang.java.programmer. Please
don't post the same questions to multiple newsgroups.

0 new messages