This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Swig" Watch "Swig" New topic
Author

Swig

bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
Hi,

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...

please..

thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

http://faq.javaranch.com/java/TellTheDetails
"Throwing some errors" is really not helpful.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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.

now,
my c program is



my interface program is,




then i give the command

swig -java example.i

it runs and generates the files,

example.java
exampleJNI.java
example_wrap.c

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-1.4.2.0/include -I/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/include/linux

it shows the errors,


th e example_wrap.c file it generated is,






kindly advise....

thanks in advance







Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.

http://www.swig.org/tutorial.html

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 (main.java) 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(example.java:16)
    at main.main(main.java:4)


  • what that signifies..

    i'm just suing that sample program...

    advise please


    thanks in advance


     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Swig