Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

JNI DLL for Windows and Linux

Samantha_G_
Beginner
1,166 Views

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?

0 Kudos
4 Replies
mecej4
Honored Contributor III
1,166 Views

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.

0 Kudos
Samantha_G_
Beginner
1,166 Views

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

0 Kudos
SergeyKostrov
Valued Contributor II
1,166 Views
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. ...
0 Kudos
J_W
Beginner
1,166 Views
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.
0 Kudos
Reply