PDA

View Full Version : [SOLVED] Java - C - CUPS - undefined Symbol in Shared Object



mike_g
August 18th, 2008, 11:49 PM
I'm making a very small DLL in C that uses CUPS and is used by Java via the JNI.

I just got hello world working from my shared object, and I changed the code to print the content of a file. When I try an call the function from Java it gives me this error:

/usr/lib/jvm/java-1.5.0-sun-1.5.0.13/jre/bin/java: symbol lookup error: /home/ricky/print_test/libprint.so: undefined symbol: cupsPrintFile
The thing I dont get is that I have cups.h included in the C source and the code would work if it was not a shared library. Anyway, this is the code I am using:

#include <jni.h>
#include <cups/cups.h>
#include "print.h"

JNIEXPORT void JNICALL Java_print_1test_Main_nativePrint
(JNIEnv *env, jobject obj)
{
cupsPrintFile("startsp", "testfile.txt", "jobby", 0, NULL);
}
And Tthis is the header that javah created for me:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class print_test_Main */

#ifndef _Included_print_test_Main
#define _Included_print_test_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: print_test_Main
* Method: nativePrint
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_print_1test_Main_nativePrint
(JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif

Would I have to add and entry for cupsPrintFile? I dident have to do that with printf.

Edit: I found my problem and it was really dumb; i forgot to add -lcups to the gcc options o_O