It's not a secret anymore!*
The moose likes Other JSE/JEE APIs and the fly likes Swig Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Swig" Watch "Swig" New topic


bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164

do anybody know how to use swig??
if anybody is aware of it, kindly tell the procedure and the working example.....

i tried with the available swig examples to create JNI wrappers etc., but it is throwing some errors...


thanks in advance.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19651
"Throwing some errors" is really not helpful.

How To Ask Questions How To Answer Questions
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
Sorry Rob,

I posted that in a haste. actually this is dragging since 1 month.. some kind of uneasiness in me.

ok fine then,

i'm using Linux. I have to create a interface for a softphone project( done in c++) in java using JNI and swings.

i tried for month and couldn't get it right.
last thursday we e-mailed to one guy who said he has done softphone interface in JAVA using JNI(just as our requirements)

he replied, in his coding he used SWIG to generate all the wrapper classes. so we moved on to SWIG.
we are just running the sample program available in google. once we succesfully run this we plan to move to our main cpp program to create wrapper classes with SWIG.

so, we downloaded the.tar SWIG file and extracted.

my c program is

my interface program is,

then i give the command

swig -java example.i

it runs and generates the files,

the I compile the example.c and example_wrap.c files with the command

gcc -c example.c example_wrap.c -I/usr/lib/jvm/java-1.4.2-gcj- -I/usr/lib/jvm/java-1.4.2-gcj-

it shows the errors,

th e example_wrap.c file it generated is,

kindly advise....

thanks in advance

Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

My_variable is not declared in that C file, nor is it in any of the included files. To be honest, it surprises me that the compiler doesn't complain about the fact, my_mod and get_time functions.

If possible, change your initial C program to this:
(looks a lot like your example.i, doesn't it )
You should then include this new header file in your example_wrap.c:
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
thank you rob..

let me check..
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi rob,

i found that the error which i got earlier disappeared when i use the coding from the following link.

now i made the changes you recommended.

it is saying "example.h" : no such file or directory in both the example.c file and the example_wrap.c file.
so i removed that.

now i created the .so file and placed that in /usr/lib folder. this is to be done because the .so file is read from that path....

now i created a java main file ( as in the above link. i compiled it too with out errors.. but when running it is showing the error in My_variable..

  • Exception in thread "main" java.lang.UnsatisfiedLinkError: exampleJNI.My_variable_get()D
    at exampleJNI.My_variable_get(Native Method)
    at example.getMy_variable(
    at main.main(

  • what that signifies..

    i'm just suing that sample program...

    advise please

    thanks in advance

    I agree. Here's the link:
    subject: Swig
    Similar Threads
    How's Satyam [Security Services] ?
    buy one song on the net
    How do I run an external tool from Ant
    Would it be any useful if...