Home » Language IDEs » C / C++ IDE (CDT) » jni code compiles on linux but now windows
jni code compiles on linux but now windows [message #216981] |
Tue, 03 June 2008 00:45  |
Eclipse User |
|
|
|
Originally posted by: dingfeldera.gmail.com
I am trying to write a cross platform jni library under eclipse on ubuntu
I am able to compile the linux version no problems.
I have tried both GCC and Mingw toolchains to try and make a windows dll
and both end up with the same 201 errors starting with:
const struct JNIInvokeInterface_’ has no member named ‘AttachCurrentThread’
This error comes from line 1896 of jni.h
which is
return functions->AttachCurrentThread(this, penv, args);
Does anyone have any insight into the cause of this?
PS: a helloworld example worked under all 3 toolchains, it is only when
I start using JNI that the windows ones stop working.
Also, I am indeed including the latest win32 includes (where jni_md.h is
found)
Thoughts?
|
|
|
Re: jni code compiles on linux but now windows [message #217085 is a reply to message #216981] |
Wed, 04 June 2008 18:55   |
Eclipse User |
|
|
|
Originally posted by: dingfeldera.gmail.com
a bit more info if it helps:
breaking up into lines for readability, the build path etc for windows
(which fails) is:
g++
-D__int64=long long
-I/home/dingfeldera/workspace/cpp.locsolve/common/jni
-I/home/dingfeldera/workspace/cpp.locsolve/common/jni/win32
-I/home/dingfeldera/workspace/cpp.locsolve/common
-I/home/dingfeldera/workspace/cpp.locsolve/locsolve
-I/home/dingfeldera/workspace/cpp.locsolve/bridge
-O2 -g -Wall -c -fmessage-length=0
-obridge/LocSolveBridge.o ../bridge/LocSolveBridge.cpp
compared to the linux path which works:
g++
-I/home/dingfeldera/workspace/cpp.locsolve/common/jni
-I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
-I/home/dingfeldera/workspace/cpp.locsolve/common
-I/home/dingfeldera/workspace/cpp.locsolve/locsolve
-I/home/dingfeldera/workspace/cpp.locsolve/bridge
-O2 -g -Wall -c -fmessage-length=0
-obridge/LocSolveBridge.o ../bridge/LocSolveBridge.cpp
as you can see there, the only difference is the jni/linux vs the
jni/win32 and the -D__int64 constant that windows requires
the first error I am getting in the windows version is
In file included from
.../bridge/com_sirtrack_common_bridge_locsolv_dll_JniLocSolv eBridge.h:2,
from ../bridge/LocSolveBridge.cpp:4:
/home/dingfeldera/workspace/cpp.locsolve/common/jni/jni.h:20 2: error:
expected `)' before ‘*’ token
the area of code where this happens is listed here, where compile error
lines are marked with -->
This is from jni.h, around line 1867
/* These will be VM-specific. */
#define JDK1_2
#define JDK1_4
/* End VM-specific. */
struct JNIInvokeInterface_ {
void *reserved0;
void *reserved1;
void *reserved2;
--> jint (JNICALL *DestroyJavaVM)(JavaVM *vm);
--> jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void
*args);
--> jint (JNICALL *DetachCurrentThread)(JavaVM *vm);
--> jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version);
--> jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void
**penv, void *args);
};
struct JavaVM_ {
const struct JNIInvokeInterface_ *functions;
#ifdef __cplusplus
jint DestroyJavaVM() {
--> return functions->DestroyJavaVM(this);
}
jint AttachCurrentThread(void **penv, void *args) {
--> return functions->AttachCurrentThread(this, penv, args);
}
jint DetachCurrentThread() {
--> return functions->DetachCurrentThread(this);
}
jint GetEnv(void **penv, jint version) {
--> return functions->GetEnv(this, penv, version);
}
jint AttachCurrentThreadAsDaemon(void **penv, void *args) {
--> return functions->AttachCurrentThreadAsDaemon(this, penv, args);
}
#endif
};
|
|
|
Re: jni code compiles on linux but now windows [message #217154 is a reply to message #217085] |
Sun, 08 June 2008 17:57   |
Eclipse User |
|
|
|
Originally posted by: dingfeldera.gmail.com
Interesting note:
I was able to get the same code to compile in Bloodshed C++ under wine
(compiling the code out of the eclipse workspace) and it build the
windows dll fine. Bloodshed was using the mingw compiler. So for the
moment, I have a workaround: use CDT for coding and building linux
libraries, and switch for bloodshed for windows.
andy dingfelder wrote:
> a bit more info if it helps:
>
> breaking up into lines for readability, the build path etc for windows
> (which fails) is:
>
> g++
> -D__int64=long long
> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/win32
> -I/home/dingfeldera/workspace/cpp.locsolve/common
> -I/home/dingfeldera/workspace/cpp.locsolve/locsolve
> -I/home/dingfeldera/workspace/cpp.locsolve/bridge
> -O2 -g -Wall -c -fmessage-length=0
> -obridge/LocSolveBridge.o ../bridge/LocSolveBridge.cpp
>
>
>
> compared to the linux path which works:
>
> g++
> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
> -I/home/dingfeldera/workspace/cpp.locsolve/common
> -I/home/dingfeldera/workspace/cpp.locsolve/locsolve
> -I/home/dingfeldera/workspace/cpp.locsolve/bridge
> -O2 -g -Wall -c -fmessage-length=0
> -obridge/LocSolveBridge.o ../bridge/LocSolveBridge.cpp
>
>
>
> as you can see there, the only difference is the jni/linux vs the
> jni/win32 and the -D__int64 constant that windows requires
>
> the first error I am getting in the windows version is
>
> In file included from
> ../bridge/com_sirtrack_common_bridge_locsolv_dll_JniLocSolve Bridge.h:2,
> from ../bridge/LocSolveBridge.cpp:4:
> /home/dingfeldera/workspace/cpp.locsolve/common/jni/jni.h:20 2: error:
> expected `)' before ‘*’ token
>
>
>
> the area of code where this happens is listed here, where compile error
> lines are marked with -->
> This is from jni.h, around line 1867
>
> /* These will be VM-specific. */
>
> #define JDK1_2
> #define JDK1_4
>
> /* End VM-specific. */
>
> struct JNIInvokeInterface_ {
> void *reserved0;
> void *reserved1;
> void *reserved2;
>
> --> jint (JNICALL *DestroyJavaVM)(JavaVM *vm);
>
> --> jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void
> *args);
>
> --> jint (JNICALL *DetachCurrentThread)(JavaVM *vm);
>
> --> jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version);
>
> --> jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void
> **penv, void *args);
> };
>
> struct JavaVM_ {
> const struct JNIInvokeInterface_ *functions;
> #ifdef __cplusplus
>
> jint DestroyJavaVM() {
> --> return functions->DestroyJavaVM(this);
> }
> jint AttachCurrentThread(void **penv, void *args) {
> --> return functions->AttachCurrentThread(this, penv, args);
> }
> jint DetachCurrentThread() {
> --> return functions->DetachCurrentThread(this);
> }
>
> jint GetEnv(void **penv, jint version) {
> --> return functions->GetEnv(this, penv, version);
> }
> jint AttachCurrentThreadAsDaemon(void **penv, void *args) {
> --> return functions->AttachCurrentThreadAsDaemon(this, penv, args);
> }
> #endif
> };
|
|
|
Re: jni code compiles on linux but now windows [message #217252 is a reply to message #217154] |
Tue, 10 June 2008 17:46   |
Eclipse User |
|
|
|
Originally posted by: dingfeldera.gmail.com
bump.
Is nobody doing cross platform JNI?
andy dingfelder wrote:
> Interesting note:
>
> I was able to get the same code to compile in Bloodshed C++ under wine
> (compiling the code out of the eclipse workspace) and it build the
> windows dll fine. Bloodshed was using the mingw compiler. So for the
> moment, I have a workaround: use CDT for coding and building linux
> libraries, and switch for bloodshed for windows.
>
> andy dingfelder wrote:
>> a bit more info if it helps:
>>
>> breaking up into lines for readability, the build path etc for windows
>> (which fails) is:
>>
>> g++
>> -D__int64=long long
>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/win32
>> -I/home/dingfeldera/workspace/cpp.locsolve/common
>> -I/home/dingfeldera/workspace/cpp.locsolve/locsolve
>> -I/home/dingfeldera/workspace/cpp.locsolve/bridge
>> -O2 -g -Wall -c -fmessage-length=0
>> -obridge/LocSolveBridge.o ../bridge/LocSolveBridge.cpp
>>
>>
>>
>> compared to the linux path which works:
>>
>> g++
>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
>> -I/home/dingfeldera/workspace/cpp.locsolve/common
>> -I/home/dingfeldera/workspace/cpp.locsolve/locsolve
>> -I/home/dingfeldera/workspace/cpp.locsolve/bridge
>> -O2 -g -Wall -c -fmessage-length=0
>> -obridge/LocSolveBridge.o ../bridge/LocSolveBridge.cpp
>>
>>
>>
>> as you can see there, the only difference is the jni/linux vs the
>> jni/win32 and the -D__int64 constant that windows requires
>>
>> the first error I am getting in the windows version is
>>
>> In file included from
>> ../bridge/com_sirtrack_common_bridge_locsolv_dll_JniLocSolve Bridge.h:2,
>> from ../bridge/LocSolveBridge.cpp:4:
>> /home/dingfeldera/workspace/cpp.locsolve/common/jni/jni.h:20 2: error:
>> expected `)' before ‘*’ token
>>
>>
>>
>> the area of code where this happens is listed here, where compile
>> error lines are marked with -->
>> This is from jni.h, around line 1867
>>
>> /* These will be VM-specific. */
>>
>> #define JDK1_2
>> #define JDK1_4
>>
>> /* End VM-specific. */
>>
>> struct JNIInvokeInterface_ {
>> void *reserved0;
>> void *reserved1;
>> void *reserved2;
>>
>> --> jint (JNICALL *DestroyJavaVM)(JavaVM *vm);
>>
>> --> jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv,
>> void *args);
>>
>> --> jint (JNICALL *DetachCurrentThread)(JavaVM *vm);
>>
>> --> jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version);
>>
>> --> jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void
>> **penv, void *args);
>> };
>>
>> struct JavaVM_ {
>> const struct JNIInvokeInterface_ *functions;
>> #ifdef __cplusplus
>>
>> jint DestroyJavaVM() {
>> --> return functions->DestroyJavaVM(this);
>> }
>> jint AttachCurrentThread(void **penv, void *args) {
>> --> return functions->AttachCurrentThread(this, penv, args);
>> }
>> jint DetachCurrentThread() {
>> --> return functions->DetachCurrentThread(this);
>> }
>>
>> jint GetEnv(void **penv, jint version) {
>> --> return functions->GetEnv(this, penv, version);
>> }
>> jint AttachCurrentThreadAsDaemon(void **penv, void *args) {
>> --> return functions->AttachCurrentThreadAsDaemon(this, penv,
>> args);
>> }
>> #endif
>> };
|
|
|
Re: jni code compiles on linux but now windows [message #217317 is a reply to message #217252] |
Thu, 12 June 2008 04:40   |
Eclipse User |
|
|
|
Originally posted by: 4cs6fcg02.sneakemail.com
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigE59111D6B032EA7930E4AE44
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
andy dingfelder schreef:
> bump.
>=20
> Is nobody doing cross platform JNI?
Oh yes, I=E2=80=99m trying to, but haven=E2=80=99t managed to get it runn=
ing either. A=20
collaborator got it to work on Mac, though, so I have good hopes we=E2=80=
=99ll=20
manage Windows eventually!
Actually, it kind of works with Cygwin, that is: it compiles, but the=20
program stalls the moment the library is loaded (strangely enough=20
somewhere in the classloader code).
As to your problem:
I do not use the -D__int64 thing, since that gives compile errors.
The command on Cygwin is the following:
library: $(OBJS)
gcc -shared -o"$(LIBRARY_NAME)" $(OBJS)
$(BINDIR)/%.o: $(SRCDIR)/%.c
gcc -c $(CFLAGS) -o"$@" "$<"
with in Windows:
CFLAGS =3D -std=3Dgnu99 $(LIBS) -O4 -Wall
#-D__int64=3D"long long" is recommended by the JNI book
#CFLAGS +=3D -D__int64=3D"long long"
#fno-strict-aliasing is needed for SWIG
CFLAGS +=3D -fno-strict-aliasing
in Linux:
CFLAGS =3D -std=3Dgnu99 $(LIBS) -O4 -Wall
#fPIC is really necessary for the linker on Linux, strange Eclipse does=20
not include it by default
CFLAGS +=3D -fPIC
#fno-strict-aliasing is needed for SWIG
CFLAGS +=3D -fno-strict-aliasing
note the difference: -fPIC not on Windows. This gave compile errors.
and
LIBS =3D \
-I$(JDK_HOME)/include \
-I$(JDK_HOME)/include/linux
I used to override LIBS on the build command for Windows, still have to=20
look whether it is possible to use JDK_HOME there as well.
The error certainly looks like a problem with the -I includes. You have =
a rather strange path there:
-I/home/dingfeldera/workspace/cpp.locsolve/common/jni
-I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
Are these symbolic links? Try using what I have, or something like=20
-IC:/Program Files/Java<or whatever>/include
If you use Cygwin, you can use Linux paths as well, such as=20
/usr/lib/java/include
Good luck, H.
--=20
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
--------------enigE59111D6B032EA7930E4AE44
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFIUOECe+7xMGD3itQRAqnCAJ452SYNgm1545AXL+ZsCBlgmWdewQCe Iqf4
Tgu+msIYMw+iVH2nXQ0ZzEY=
=b8Y+
-----END PGP SIGNATURE-----
--------------enigE59111D6B032EA7930E4AE44--
|
|
|
Re: jni code compiles on linux but now windows [message #217400 is a reply to message #217317] |
Fri, 13 June 2008 18:50   |
Eclipse User |
|
|
|
Originally posted by: dingfeldera.gmail.com
> The error certainly looks like a problem with the -I includes. You have
> a rather strange path there:
>
> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
>
> Are these symbolic links? Try using what I have, or something like
> -IC:/Program Files/Java<or whatever>/include
I did this as my goal is that I want to be able to compile for either
windows, mac or linux.
For example, the project structure contains:
/common/jni
/common/jni/win32
/common/jni/mac
/common/jni/linux
/common/jni contains the stuff from /usr/lib/java/include
/common/jni/linux contains the stuff from /usr/lib/java/include/linux
/common/jni/win32 contains the stuff from C:/Program
Files/Java/include/linux
/common/jni/mac is empty at the moment as I dont have those files yet.
Perhaps the confusing thing is the name jni... I guess the include
directory contains more than just JNI stuff so a better naming structure
would be something like
/common/jre_include
/common/jre_include/win32
/common/jre_include/mac
/common/jre_include/linux
RE The reason I did not link directly to the jvm/include/linux is that I
want to have the project checked into svn and have to build on either
windows or linux, and that link would only be available on linux.
Does that make sense?
I am actually a bit frustrated that the java distribution does not have
the include files for all OSes included already.
> If you use Cygwin, you can use Linux paths as well, such as
> /usr/lib/java/include
I have Cygwin installed on my windows box but am not using it currently
as I am now migrated 99% to linux. Bloodshed c++ compiles successfully
for windows using ming32 under linux wine, so even if I can not get
linux eclipse cdt with JNI to work for windows, I can get by for the moment.
Cheers,
Ding
|
|
|
Re: jni code compiles on linux but now windows [message #217447 is a reply to message #217400] |
Mon, 16 June 2008 05:16   |
Eclipse User |
|
|
|
Originally posted by: 4cs6fcg02.sneakemail.com
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigFC588D305CAEF0948ACF00AB
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
andy dingfelder schreef:
>> The error certainly looks like a problem with the -I includes. You=20
>> have a rather strange path there:
>>
>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
>>
>> Are these symbolic links? Try using what I have, or something like=20
>> -IC:/Program Files/Java<or whatever>/include
>=20
> I did this as my goal is that I want to be able to compile for either=20
> windows, mac or linux.
<snip>
Fine, if you want to do it that way. However, I=E2=80=99d first suggest =
you try=20
to get it to run with the original java include path, then migrate those =
files, maybe something went wrong in the process.
> RE The reason I did not link directly to the jvm/include/linux is that =
I=20
> want to have the project checked into svn and have to build on either=20
> windows or linux, and that link would only be available on linux.
>=20
> Does that make sense?
>=20
> I am actually a bit frustrated that the java distribution does not have=
=20
> the include files for all OSes included already.
Indeed, that=E2=80=99s unnecessary sparseness.
Good luck to both of us=E2=80=A6
H.
--=20
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
--------------enigFC588D305CAEF0948ACF00AB
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFIVi9re+7xMGD3itQRAk8XAJ9LORh2bOPCN+jIvnBKgNsj6qLCPgCf Wlh6
nNSduHROGhLhadm5Es3LJRM=
=uLFY
-----END PGP SIGNATURE-----
--------------enigFC588D305CAEF0948ACF00AB--
|
|
|
Re: jni code compiles on linux but now windows [message #218320 is a reply to message #217447] |
Tue, 01 July 2008 18:21  |
Eclipse User |
|
|
|
Originally posted by: dingfeldera.gmail.com
Still broken with CDT 5.0 btw.
:(
Hendrik Maryns wrote:
> andy dingfelder schreef:
>>> The error certainly looks like a problem with the -I includes. You
>>> have a rather strange path there:
>>>
>>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni
>>> -I/home/dingfeldera/workspace/cpp.locsolve/common/jni/linux
>>>
>>> Are these symbolic links? Try using what I have, or something like
>>> -IC:/Program Files/Java<or whatever>/include
>>
>> I did this as my goal is that I want to be able to compile for either
>> windows, mac or linux.
>
> <snip>
>
> Fine, if you want to do it that way. However, I’d first suggest you try
> to get it to run with the original java include path, then migrate those
> files, maybe something went wrong in the process.
>
>> RE The reason I did not link directly to the jvm/include/linux is that
>> I want to have the project checked into svn and have to build on
>> either windows or linux, and that link would only be available on linux.
>>
>> Does that make sense?
>>
>> I am actually a bit frustrated that the java distribution does not
>> have the include files for all OSes included already.
>
> Indeed, that’s unnecessary sparseness.
>
> Good luck to both of us…
>
> H.
|
|
|
Goto Forum:
Current Time: Wed May 07 03:27:56 EDT 2025
Powered by FUDForum. Page generated in 0.03890 seconds
|