因为做项目,从网上找了一个类似的源码,但是是java和c混合编译的。我试了用javah编译下面那个SrDesign.java文件再重新编译工程,也通过不了,显示的信息为
Exception in thread "main" java.lang.UnsatisfiedLinkError: no qcSys in java.libr
ary.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
        at java.lang.Runtime.loadLibrary0(Runtime.java:845)
        at java.lang.System.loadLibrary(System.java:1084)
        at SrDesign.<clinit>(SrDesign.java:145)
求大侠帮忙,我贴出来的是不完全的代码,因为字数限制,有需要的我可以都给你,在线等解答。*** qcSys.c
// qcSys -- the all important C function, to allow access to the QuickCam
// this source code, along with some other autogenerated and
// system standard headers, etc. are compiled into a shared library
// which is loaded by the Java system to provide access to the
// function in this file// we need some standard Java (StubPreamble) and C (stdio) header files
#include <StubPreamble.h>
#include <stdio.h>// and the header file for the native function, generated by the javah
// program, which is part of the JDK
#include "SrDesign.h"// the function, with header as javah (and Java) understands it
// Java structures are accessed via the unhand() call which
//  provides us with a pointer to the Java structure.
//  A Java byte array is equivalent to a C char array
// The function operates by opening a pipe from the command
// requested by the main (run) loop and fget'ting that data
// into a character array
void SrDesign_qcSys(struct HSrDesign *this,
struct Hjava_lang_String *command,
HArrayOfByte *byteImage)
{
char *QCimage = unhand(byteImage)->body;
int length = obj_length(byteImage);
FILE *fp; fp = popen(makeCString(command),"r"); fgets(QCimage, length, fp);
return;
}
*** SrDesign.java
// SrDesign -- the main body of code for the video conferencing
// portion of the Intelligent Video Conferencing project
// Copyright 1996-1997, Apu <[email protected]> and Joanna Welenc
// Created for Stevens Institute of Technology EE/CS 415/416
// Dr. Stanley Smith, Advisor
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;public class SrDesign extends Applet implements Runnable
{
// global variables
Thread animThread;
ObservableInt brightness, contrast, whitebal;
ObservableString remoteAddr;
Frame ControlPanel;
Image qcLocal, qcRemote;
byte[] byteImgLocal = new byte[24475];
byte[] byteImgRemote = new byte[24475];
static boolean inApplet=true; // application startup
public static void main(String args[])
{
inApplet = false;
Frame applFrame = new Frame("SrDesign");
Applet SDappl = new SrDesign();
SDappl.init();
SDappl.start();
applFrame.setLayout(new FlowLayout());
applFrame.add(SDappl);
applFrame.resize(640,240);
applFrame.show();
} // initialization
public void init()
{
// default values
brightness = new ObservableInt(135);
contrast = new ObservableInt(215);
whitebal = new ObservableInt(150);
remoteAddr = new ObservableString("localhost"); // create and add Control Panel frame
ControlPanel = ControlPanel("SrDesign - Controls");
} public void start()
{
// start animation Thread
if (animThread == null)
{
animThread = new Thread(this);
animThread.start();
}
} public void stop()
{
// stop animation Thread -- called by system on stopping
animThread.stop();
animThread = null;
} // what do we repaint
public void paint(Graphics g)
{
g.drawImage(qcLocal, 0, 0, this);
g.drawImage(qcRemote, 320, 0, this);
} // the main loop of the program
public void run()
{
// the command sent to the C library is stored
// in a local string
String command; Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
while (true)
{
try
{
// sleep for a while to let other stuff
// do its thing
animThread.sleep(100); // Construct command string with current
// values of the the observables
// and get image
command = "qcam " +
" -b " + brightness.getValue() +
" -c " + contrast.getValue() +
" -w " + whitebal.getValue() +
" | ppmtogif"; qcSys(command, byteImgLocal);
qcLocal = createImage(new
MemoryImageSource(
320, 240,
ColorModel.getRGBdefault(),
byteImgLocal, 0, 0)); // send image to remote party
InetAddress internet_addr =
InetAddress.getByName(remoteAddr.getValue());
int port = 2000;
DatagramPacket snd_packet = new
DatagramPacket(
byteImgLocal, 24475,
internet_addr, port);
DatagramSocket snd_socket = new
DatagramSocket();
snd_socket.send(snd_packet);
snd_socket.close(); // and receive a frame from them
DatagramPacket rcv_packet = new
DatagramPacket(byteImgRemote,
byteImgRemote.length);
DatagramSocket rcv_socket = new
DatagramSocket(port);
rcv_socket.receive(rcv_packet);
rcv_socket.close(); // and now repaint both on screen
repaint();
}
catch (Exception sleepProblem)
{ }
}
} // the qcSys function is implemented in native (non-Java) code
// we just need the prototype for others to use it
public native void qcSys(String command, byte[] byteImgLocal); // (we need to load in the non-native code to be able to access it)
static
{
System.loadLibrary("qcSys");
} // the ControlPanel is implemented as a separate frame so that
// we can collapse (minimize) it out of the way when we
// don't need it
private Frame ControlPanel(String label)
{
Frame frame = new Frame(label); Panel panel;
IntScrollbar scrollbar; GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.anchor = GridBagConstraints.WEST;
constraints.gridwidth = GridBagConstraints.REMAINDER;
frame.setLayout(gridbag); panel = IntControl("Brightness",brightness);
gridbag.setConstraints(panel, constraints);
frame.add(panel); scrollbar = new IntScrollbar(brightness,
Scrollbar.HORIZONTAL,
0, 10, 0, 255);
gridbag.setConstraints(scrollbar, constraints);
frame.add(scrollbar); panel = IntControl("Contrast",contrast);
gridbag.setConstraints(panel, constraints);
frame.add(panel); scrollbar = new IntScrollbar(contrast,
Scrollbar.HORIZONTAL,
0, 10, 0, 255);
gridbag.setConstraints(scrollbar, constraints);
frame.add(scrollbar); panel = IntControl("White Balance",whitebal);
gridbag.setConstraints(panel, constraints);
frame.add(panel); scrollbar = new IntScrollbar(whitebal,
Scrollbar.HORIZONTAL,
0, 10, 0, 255);
gridbag.setConstraints(scrollbar, constraints);
frame.add(scrollbar); panel = StringControl("Remote Party",remoteAddr);
gridbag.setConstraints(panel, constraints);
frame.add(panel); frame.resize(225,275);
frame.show();
return frame;
} // parts for the ControlPanel implementing varies other classes
// remember, Java is an object-oriented language; the other
// classes are reusable, and hence not included as part of
// this file
private Panel IntControl(String label, ObservableInt variable)
{
Panel panel = new Panel(); panel.add(new Label(label));
panel.add(new IntTextField(variable)); return panel;
} private Panel StringControl(String label, ObservableString variable)
{
Panel panel = new Panel();
Label lbl;
StringTextField field; GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridwidth = GridBagConstraints.REMAINDER;
panel.setLayout(gridbag); lbl = new Label(label);
gridbag.setConstraints(lbl, constraints);
panel.add(lbl); field = new StringTextField(variable);
gridbag.setConstraints(field, constraints);
panel.add(field); return panel;
}
}