javagcj

GCJ: Java native code, won't run on other machines


I tried GCJ and it compiled fine. I tried both for Ubuntu and windows. The compiled file is running on my Ubuntu machine as well the .exe with wine. But if I tried to run in on my Ubuntu server I got this error:

error while loading shared libraries: libgcj.so.14: cannot open shared object file: No such file or directory

But I thought I would not need to install anything to run "native" code. I also could not run the .exe on a windows machine.

Could you please tell me why this is happening? Maybe I'm compiling wrong. I use this: gcj --main=Hello -o hello.exe Hello.jar for windows.


Solution

  • When you run an executable it is very common to need a shared library, whether you use Visual Studio .NET or Java or C++.

    When you compile a program for a specific platform, it usually only works on that platform or similar. If you want to run this program on Windows, you need to compile it for windows.

    BTW GCJ is pretty old and out of date. I suggest you use Java 7 or 8. This will avoid the need to install additional libraries and will run on Windows or Linux without re-compiling.