I get the following error message, yet don’t seem able to get past it. I am probably missing something in the link line of the makefile but can’t see what library I am missing. I’ve written a simple JNI Hello World and simple OpenGL program using a very similar makefile (modified to produce an executable rather than a shared lib for the OpenGL program), which both run without a problem.
Exception in thread “main” java.lang.UnsatisfiedLinkError: /uufs/chpc.utah.edu/common/home/u0544384/Desktop/OpengL_Test/libMyWindow.so: /uufs/chpc.utah.edu/common/home/u0544384/Desktop/OpengL_Test/libMyWindow.so: undefined symbol: JAWT_GetAWT
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at MyWindow.(MyWindow.java:14)
Could not find the main class: MyWindow. Program will exit.
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Label;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Graphics;
import javax.swing.Timer;
public class MyWindow extends Canvas implements ActionListener
{
static {
System.out.println( "java.library.path := " + System.getProperty("java.library.path") );
System.loadLibrary("MyWindow");
}
public final static int TIMER_SECONDS = 100;
public static void main( String[] argv )
{
Frame f = new Frame();
f.setSize(300,400);
f.setLayout(new BorderLayout());
f.setTitle("OpenGL from Java");
MyWindow w = new MyWindow();
f.add(w,BorderLayout.CENTER);
f.add(new Label("test"),BorderLayout.SOUTH);
f.setBounds(300,300,300,300);
f.setVisible(true);
}
private boolean bInitOpenGL = false;
public void actionPerformed(ActionEvent evt)
{
if(bInitOpenGL == false)
{
bInitOpenGL = true;
initializeOpenGL();
}
paintOpenGL();
}
public void addNotify()
{
super.addNotify();
javax.swing.Timer timer = new Timer(TIMER_SECONDS,this);
timer.start();
}
public void removeNotify()
{
super.removeNotify();
cleanupOpenGL();
}
// native entry point for Painting
public native void paintOpenGL();
// native entry point for enabling OpenGL calls.
public native void initializeOpenGL();
// native entry point for disabling OpenGL calls.
public native void cleanupOpenGL();
}
CC = gcc -pedantic -ansi -shared
SRC = MyWindow.cpp
all:
$(CC) $(SRC) -o libMyWindow.so -L/usr/X11R6/lib -lGL -lGLU -lXxf86vm -lstdc++
clean:
@echo Cleaning up...
@rm -f *.so *.o
@echo Done.