0

I am currently developing on a 64-bit Windows 7 machine. I have JRE7 64-bit and JRE7 32-bit installed on my machine. I am using Eclipse 64-bit version and configured Window - Preferences - Java - Installed JREs to use JRE7 32-bit to be my default JRE to test against. Also installed the 32-bit JDK and currently using that to test against.

I double checked and made sure I am indeed using SWT 32-bit Windows but still during compilation it throws me the "Cannot load 64-bit SWT libraries on 32-bit JVM" error.

The error clearly indicates that Eclipse is indeed using JDK7-32 Bit but for some reason the SWT Libraries (http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.3-201306052000/swt-4.3-win32-win32-x86.zip) is not fully 32-bit o.O...

Any ideas? Any workarounds?

FYI, switching the JRE to 64-bit compiles the program just fine but I want my application to work on both 32-bit and 64-bit.

Here is the full exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 64-bit SWT libraries on 32-bit JVM
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:260)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
    at org.eclipse.swt.internal.C.<clinit>(C.java:21)
    at org.eclipse.swt.widgets.Widget.<clinit>(Widget.java:107)
    at Test.Application.<init>(Application.java:19)a
    at Test.Application.main(Application.java:29)
roosevelt
  • 1,874
  • 4
  • 20
  • 27

3 Answers3

3

SWT uses plugin fragments to control this - there is a 32-bit fragment and a 64-bit fragment (as well as fragments for Mac, Linux, etc). Make sure your launch configuration is set to use the proper fragment depending on which JVM you're running it on.

As a note, just including "both" plugin fragments will not work, as then they will both attempt to load and cause problems.

Also, this related question may be useful.

Another idea would be to dive into the loadLibrary function - from what I remember of how that works, it looks for a cached version of the SWT dll from a temp location somewhere, and so it might be using a cached 64-bit dll instead of properly unpacking the 32-bit one from the jar. In that case, deleting the cached one may fix the issue.

The easiest solution, though, may be just to have two separate instances of Eclipse: one setup to run 32-bit, one setup to run 64-bit. This way you don't have to worry about toggling back and forth, or futz around with configurations as much.

Community
  • 1
  • 1
Krease
  • 15,805
  • 8
  • 54
  • 86
  • That might be the missing ingredient... do you have an example code or a screenshot? Because all I did is I downloaded http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops4/R-4.3-201306052000/swt-4.3-win32-win32-x86.zip, added the swt.jar to Java Build Path - Libraries and tried to execute my sample swt project. And ran into the above error. – roosevelt Feb 24 '14 at 01:05
  • Sorry, can't make a screenshot at the moment. You should be able to find the list of plugins in the launch configuration in the 'Plugins' tab of your Run/Debug Configuration dialog (the one with Main, Arguments, Plugins, Configuration, etc) that you use to setup your environment). Scroll through the list and make sure to only select the correct SWT for the architecture you're running on. – Krease Feb 24 '14 at 01:11
  • Added another idea in edit - you can side-by-side instances of Eclipse, eliminating the need to "configure" your 64-bit version to use 32-bit things and vice versa. – Krease Feb 24 '14 at 01:14
  • http://stackoverflow.com/a/21077768/836214 may be useful as well - haven't tried it myself though. – Krease Feb 24 '14 at 01:16
  • hmm... I think you are misunderstanding the error. The issue is not with Eclipse or even Java. I downloaded 32-bit SWT Windows. I am compiling my application using the 32-bit JDK. But the error says that I am using 64-bit SWT Windows. So, the issue is not eclipse or java but the SWT 32-bit I downloaded is probably corrupted or misleading or I am missing a step somewhere. Thanks for the effort though, I am reviewing some of your suggestions. – roosevelt Feb 24 '14 at 01:19
  • Ahh, I must have missed that. Another idea would be to dive into the `loadLibrary` function - from what I remember of how that works, it looks for a cached version of the SWT dll from a temp location somewhere, and so it might be using a cached 64-bit dll instead of properly unpacking the 32-bit one from the jar. In that case, deleting the cached one may fix the issue. – Krease Feb 24 '14 at 01:30
  • Hey man, you are a life saver. I found the problem... what happened was when I started a SWT Project in eclipse... it automatically grabbed org.eclipse.swt.win64....! I saw that by debugging the loadLibrary method() and removing the 64bit version and re-importing my 32-bit version solved the problem! – roosevelt Feb 24 '14 at 01:52
  • 1
    Glad to hear. I'll edit that part into my answer so it's not just buried in the comments. – Krease Feb 24 '14 at 02:00
0

"I am using Eclipse 64-bit version and configured Window - Preferences - Java - Installed JREs to use JRE7 32-bit to be my default JRE to test against."

how about configure your eclipse to point and use a full blown 32-bit jdk instead of the jre for the project?

user3206144
  • 606
  • 4
  • 5
  • FYI the issue is not with JDK or Java at all. From the looks of the error message, SWT-32 bit is not really 32-bit o.O – roosevelt Feb 24 '14 at 01:06
0

In your Eclipse click on

Run -> External Tools -> External Tools Configurations...

In JRE tab Choose the option

Run in the same JRE as workspace.


This fixed the issue for me.