JNI DLL for Windows and Linux

JNI DLL for Windows and Linux

Hello,

I built a C++ DLL on Windows using Visual Studio 2010 with a Fortran library I built with the Intel compiler.

I then loaded it into my Java program. Everything works fine on the PC side.  When I put my code over to the LINUX side, java gives me this error message: invalid ELF header (Possible cause: endianness mismatch) about my DLL file.

A quick google search has suggestions to add "-fPIC" to their gcc compiler/linker command.  Is there an equivalent for Visual Studio?  Does this mean I need to have two DLLs built?  One for Windows and One for LINUX?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

No object files, EXE files and DLLs built on Windows will work in Linux (unless you are running inside a VM). The only items that may be moved, and even then some changes may be needed, are HLL program source (Fortran, C, Java) files, Java class files, text data files and some makefiles.

I think that must be my problem then.  I run the JVM on Windows and on LINUX.

Samantha, you need to have two different projects, that is, one for Windows and another one for Linux OSs. When a binary is built for Windows it can not be used on Linux.

The -fPIC option of GCC compiler has no equivalent for Microsoft's C++ compilers. ( PIC means position-independent code ). Here is a quote from GCC docs:

...
`-fPIC'
If supported for the target machine, emit position-independent
code, suitable for dynamic linking and avoiding any limit on the
size of the global offset table. This option makes a difference
on the m68k and the SPARC.

Position-independent code requires special support, and therefore
works only on certain machines.
...

Just as Sergey said,DLL file only works on Windows. You need recompile all the source code (both Java and C) in Linux to generate the corresponding binary files.

Use GCC to compile the C/C++ code, but before that, usually a makefile is needed . Some efforts need to make, when you migrate projects between Windows and Linux.

coding for fun

Leave a Comment

Please sign in to add a comment. Not a member? Join today