0

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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Joey
  • 809
  • 1
  • 10
  • 24

1 Answers1

3

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Do you mean by "compile it for windows" compile it **on** windows? Because I compiled it for windows with the line I mentioned, didnt'I? But my goal was do avoid that the user needs to install the JRE. – Joey Dec 13 '14 at 14:32
  • @st1n You need to build the software for each type of system it could be installed on. You also need to install the shared libraries needed. – Peter Lawrey Dec 13 '14 at 14:41
  • Do you mean by "each type of system" for windows 7,8 etc. or really for the machine of friend1, friend2, friend3? BTW thank you for your help :) – Joey Dec 13 '14 at 14:43
  • It depends on the application, but usually a Windows 7 programs run on Windows 8.1. Of course the program won't be as optimised as you need to statically compile for the lowest common system. – Peter Lawrey Dec 13 '14 at 14:50