USING AN EXISTING C++ DLL WITH JNI

I'm under Unix Solaris with the CC compiler.
I have a C++ DLL, called "libtest.so", that I would like to execute from Java thanx to JNI.
I have built a wrapper DLL, called "libwrapper.so", that contains my native method.
"libwrapper.so" talks properly with Java when I don't link it with "libtest.so" and "libtest.so" runs properly when I call it from a main function in C++.
But as I want to link them (with the option -ltest in the compilation command that I launch to get "libwrapper.so"), I get the following message error when I execute my java application : "Can't load library libwrapper.so "
How can I link "libwrapper.so" and "libtest.so" to get a wrapper
DLL that is loadable by Java ?
Can you help me to solve my problem ?
Thanx
Steph

Every native library must be explicitly loaded by java code before it is referenced.
If your libtest.so is referenced by libwrapper.so, a call to LoadLibrary("wrapper") will
cause a reference to libtest.so, which will try to load it (unix in this case) by looking for it on
the LD_LIBRARY_PATH, where it won't find it.
To fix this call LoadLibrary("test") first, before LoadLibrary("wrapper").

Similar Messages

  • Calling an existing C code with JNI under linux.

    Hi all,
    I am trying to use an exsiting c code with jni but I am keep getting
    java.lang.UnsatisfiedLinkError, I am working under linux.
    This is what I have done so far:
    1.export LD_LIBRARY_PATH='pwd'/lib
    2. created HspellNative.java with the static System.loadLibrary("HspellNative") and native function called hspellInit
    3. compiled the java class
    4. javah -jni HspellNative
    5. HspellNative.c:
    #include <jni.h>
    #include <stdio.h>
    #include "HspellNative.h"
    #include "hspell.h"
    JNIEXPORT jint JNICALL
    Java_HspellNative_hspellInit ( JNIEnv* env, jobject obj )
         struct dict_radix **dict;
         return ( (jint) (hspell_init(dict,0) ) );
    6. could be the problematic one:
    gcc -o lib/libHspellNative.so -shared -I/opt/bea/jdk142_05/include -I/opt/bea/jdk142_05/include/linux hspell.c HspellNative.c
    7. java HspellNative
    8. getting the following error:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/haim/Hspell/hspell-0.9/lib/libHspellNative.so: /opt/haim/Hspell/hspell-0.9/lib/libHspellNative.so: undefined symbol: hspell_debug
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1511)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:834)
    at HspellNative.<clinit>(HspellNative.java:18)
    My problem is that I don't know how to combine my HspellNative.c to the existing hspell.c, I know I should put them together in the shared library somehow, but how ?
    Please advice.
    Thanks in advance,
    Haim.

    I know there is something wrong with the .so, the question is: what ? and how do I fix it ?
    This is the ldd ldd libHspellNative.so output:
    /etc/libcwait.so => /etc/libcwait.so (0x0060b000)
    libc.so.6 => /lib/tls/libc.so.6 (0x00111000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00359000)
    I have no idea what it means...
    I think I will try the SWIG.
    Thanks any way.

  • How to use VS2005 dlls with jni?

    Hello,
    I have a java application using jni and some dlls.
    Previously this dlls were created using VS2003. Now I want to use VS2005 and I
    encountered some problems.
    Everything is working on my station were I have installed VS2005 but when I try to run the
    application on other station (a test station) is not working.
    I get the following error:
    java.lang.UnsatisfiedLinkError: C:\App\Test.dll: This application has failed to start because
    the application configuration is incorrect. Reinstalling the application may fix this problem
         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
         at java.lang.ClassLoader.loadLibrary0(Unknown Source)
         ......First I tried to search all the dependences and copied all missing dlls from my work station to the test
    station in the application directory. Still not working.
    when dlls were made with VS2003 I had only 3 dependences: mfc71d, msvcp71d, msvcr71d. With this dlls in
    the application directory everything was fine.
    Second I tried to install .Net framework(2.0) and vcredist (VS2005_sp1) but still nothing.
    What I'm doing wrong? Is somebody which is using dlls made in VS2005 with jni?
    Thank you
    ,Dragos

    IIRC, that message means the manifest file in the DLL points to assembly that your computer doesn't have, or it has no manifest file.
    You either need to:
    -recompile using static linking so that it has no dependencies
    -stick the correct manifest in
    -include the entire SxS (site by side) assembly folders with your application (only the ones you're dependent on). These are found in something similar to:
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86

  • Access to DLLs with JNI??

    Hi All,
    I�ve just created a DLL in VC++ version 6
    I�m using simulation packages to access functions within this DLL, this runs just fine.
    My question is: -
    How can I get my java application to access the DLL functions as well?
    If I use JNI my simulation models don�t recognise the functions anymore.
    Is there any other way of accessing my DLLs without using JNI?
    Any solution would be much appreciated.
    John.

    No luck this time either:
    Here is the code that I'm using
    (1)
    //hello.java
    class HelloWorld
    public native long displayHelloWorld();
    static
    System.loadLibrary("control_unit");
    public static void main(String[] args)
    long temp = 0;
    temp = new HelloWorld().displayHelloWorld();
    System.out.println("The returned value is "+temp);
    (2)
    // HelloWorldImp.c
    #include "stdafx.h"
    #include<stdlib.h>
    #include<stdio.h>
    #include<iostream.h>
    #include "jni.h"
    #include "HelloWorld.h"
    BOOL APIENTRY DllMain( HANDLE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved )
    return TRUE;
    DWORD WINAPI returnValue()
    return 8;
    JNIEXPORT jlong JNICALL
    Java_HelloWorld_returnValue(JNIEnv *env, jobject obj)
    return (jlong)returnValue();
    (3)
    //Generated File
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include "jni.h"
    /* Header for class HelloWorld */
    #ifndef IncludedHelloWorld
    #define IncludedHelloWorld
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: HelloWorld
    * Method: displayHelloWorld
    * Signature: ()J
    JNIEXPORT jlong JNICALL Java_HelloWorld_displayHelloWorld
    (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif
    (4)
    //Commands used
    javac hello.java
    javah HelloWorld
    cl -Ic:\jdk1.2.2\include -Ic:\jdk1.2.2\include\win32 -LD HelloWorldImp.c -Fecontrol_unit.dll
    However I usually build the dll in VC++ ver 6 as this allows my dlls to work with my sim models
    I only use the CL to get the JNI working
    And when I try to run the java application I get the following: -
    Exception in thread "main" java.lang.UnsatisfiedLinkError: displayHelloWorld
    at HelloWorld.main(hello.java:13)
    Which is "temp = new HelloWorld().displayHelloWorld();" in hello.java
    Any reason as to why it's not working?
    If you have any questions please let me know and I'll get back to you.
    Am I building the dll in the wrong manner?
    Thanks again,
    John.

  • How to use a C# dll with JNI

    After a ton of issues, I finally got this working properly. I've come across a lot of forum posts about the various problems and VERY few answers so I thought I would post my solution here.
    To do this, you need to create a managed C++ layer in between C# and java. The JNI functions in C++ dll can make calls to the C# dll directly, and your java program can make calls directly to the native JNI functions. Some important notes on using C# classes in C++ are:
    -gcroot<CSClass ^> should be used on any objects that are instances of some C# class.
    -the symbol ^ should be used with all C# references (its the symbol for references)
    -gcnew should be used to allocate C# objects
    -in visual studio, add the C# dll as a reference rather than using #using <CsDLL.dll>
    -do not use #using <CsDLL.dll>
    The next issue is loading the libraries. By adding the folder your C++ dll is located in to the Djava.library.path VM argument, you can load your C++ library with System.LoadLibrary("Cppdll.dll"). You DO NOT need to load the C# dll in your java program. In fact, it will ignore you if you try. The problem with loading this dll is with how the CLR searches for referenced assemblies. The CLR First searches the DEVPATH environment variable (if the machine.config file has developer mode set to on), then it searches the GAC, then it searches the codebases, then it searchs the current executable's directory along with a list of definable subdirectories (probes).
    DEVPATH is a decent option, but it requires modifying the machine.config file to be in developer mode. Once that is done, it acts just like the PATH environment variable.
    If your C# dlls are strongly named, I would recommend adding them to the GAC or using codebases. However I have not done this and am not sure how.

    Hi,
    i have to use a c# dll in my java program .by following this link http://www.codeproject.com/KB/cross-platform/javacsharp.aspx i done that.but it is working for only one c# program.if i am trying to use a dll it is throwing error
    # An unexpected error has been detected by Java Runtime Environment:
    # Internal Error (0xe0434f4d), pid=3988, tid=3704
    # Java VM: Java HotSpot(TM) Client VM (11.0-b16 mixed mode, sharing windows-x86)
    # Problematic frame:
    # C [kernel32.dll+0x442eb]
    # An error report file with more information is saved as:
    # D:\Work\EclipseWorkspace\HelloInflux\hs_err_pid3988.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    Please help me out. i want a few steps to invoke a c# dll by using jni

  • Cannot create dll with JNI

    hi all,
    i have a c++ coding for a softphone. I opened that file in vc++ and i'm able to create a .exe file from that.
    the .exe file is running fine( it is searching for the server and is getting registered there).
    now i wanted to add jni to it.
    so i have written a java program to one of the methods in the c++ program( void pjstart() ), compiled it and created a header file.
    now i replaced the c++ function with the stuff generated in the header file,( JNIEXPORT void JNICALL Java_test_pjstart(JNIEnv *env, jobject jobj) )
    now i'm unable to build that file in vc++. it is showing some errors..

    You need to start by creating a dll project in VC using a wizard. That should compile, build and you can even load it in java although it won't do anything.
    Then you implement the signatures provided in the h file that you get from javah.

  • Using condor engineering busapi.dll with lv 6.1

    hi all
    im trying to control a condor 1553 pci card using this dll, busapi32.dll.
    my question is this, when i load the dll using the call library function node i get the full list of functions on the dropdown, but when i select one e.g. BusTools_BC_Init the function prototype is as follows: void BusTools_BC_Init(void).
    However the function itself actually includes the following parameters  
    BT_INT BusTools_BC_Init (BT_UINT wCardnum, BT_UINT wChannel,
    BT_U32BIT dwIntEnable, BT_U16BIT wRetry,
    BT_UINT wTimeout1, BT_UINT wTimeout2,
    BT_U32BIT dFrame, BT_UINT num_buffers);
    would i be right in saying that if i added these parameters so that i got the following function prototype:
    void BusTools_BC_Init(long wCardnum, long wchannel, unsigned long dwIntEnable, unsigned short int wRetry, long wTimeout1, long wTimeout2, unsigned long dFrame, long wCardnum);
     this would then work?
    many thanks in advance (as i sometimes forget afterwards)

    Return type for BC_Init is a long...the remaining arguments are unsigned long with the exception of wRetry which is unsigned short.
    BTW: The cost for the LabVIEW driver was peanuts compared to the $9000 for the card. Besides,
    you'll spend a lot more in labor doing it the other way. That's always
    a convincing argument to management.
    Message Edited by Bill@NGC on 07-31-2007 10:55 PM
    “A child of five could understand this. Send someone to fetch a child of five.”
    ― Groucho Marx

  • How can I use an existing iTunes library with a new iTunes account

    My daughter is going to college, and wants to untangle herself from the family iTunes account. Right now, we have three iPods with libraries on three computers, all using my iTunes account - and have had no problems.
    She has signed up for a new account, but her previously purchased songs (on my account) won't play on her computer (new computer, iTunes is currently almost empty library), because it is authorized to HER iTunes account.
    What is the best way to import her iTunes library that was created using my account onto her new computer? (Old library is on a PC, she now has an iBook, purchased used on eBay.) Is there any way to get these songs to play using her new account info? Can I maybe copy them somewhere without the metadata and then move them into her library? I realize that would lose ratings and other info, but would it get rid of the block? I'm not trying to do anything dishonest - these are personal iPods, personal computers, all within one family, we've paid for all music on them.
    Any advice is greatly appreciated!
    (I posted this in the iTouch discussion, and then thought it wuold be better answered over here.)

    Then can her computer be authorized to both accounts?
    Absolutely. You can authorize any given computer to up to five iTunes Store accounts.
    If purchases are made on her account, to a computer authorized to my account, can I put those songs on my iPod?
    If you connect your iPod to her computer, yes. Tracks download only to the computer from which they're purchased, regardless of which iTunes Store account is used for the purchase. Or you could copy the tracks from her computer to yours and then authorize your computer to her iTunes Store account. But that's sort of defeating the original purpose, it would seem to me.
    is it better to buy music through Amazon downloads and/or actually purchasing CDs to avoid the security features iTunes puts on its music?
    That's certainly an option. If it's an entire album I want, I buy CDs. That way I can import them at the quality I want and to whichever of my systems I want. Amazon or one of the other download stores that offer tracks as MP3 are also an option, though for me download stores are best when you just want a couple of tracks off a given CD.

  • How do I use an existing cfp program with a new unit?

    I have an existing compact fieldpoint setup (IAK file & Programs) that I would like to install on a new unit.  How can this be achieved?

    Hi DavK.  Unfortunately there can be a lot of 'well, that depends' in how you go about moving an application
    to a new FieldPoint controller.  The following is based on the assumption that you do not have the development
    environment available; if you do, it is probably easier to just recompile targeting the new controller.
    The exe is fairly easy:
    1) ftp into the controller
    2) cd to ni-rt\startup
    3) rename startup.exe or startup.rtexe to 'something else'
    4) delete 'something else'
    5) ftp in the new startup.exe or startup.rtexe
    6) ftp in any supporting files (i.e. for external calls)
    7) in c:\ni-rt.ini set  RTTarget.ApplicationPath=c:\ni-rt\startup\startup.exe (or .rtexe)
    8) in c:\ni-rt.ini set RTTarget.LaunchAppAtBoot=True
    The .iak setting is probably easiest to re-create with MAX, rather than copy in.
    The depends part comes in with how the I/O channels were named or referenced in the .exe.  As long
    as everything was done in a generic (consistent between controllers) way you could be ok.
    My guess is that if you have trouble it will be here.
    Hope that helps.
    Matt

  • Using my existing Livebox wifi with airport extreme n

    Hi
    I have two laptops (windows) and wireless broadband supplied by an Orange livebox, one laptop connected to a printer and the other not connected to the printer, I bought a new airport extreme n base station so that I could print from either laptop and share an external hard drive...sounded pretty straight forward until I tried to put things into practice.
    Problem is I want the printer and livebox in completely different places and dont want cables between them but the option in Utilities asks to connect the extreme and livebox by ethernet, works when I do this but I want wireless!!!
    Can anyone till me if this is possible or wil I need an extra base station (dont fancy spending another £130)

    Hello AMG22. Welcome to the Apple Discussions!
    To extend an existing wireless network wirelessly, you would need to create a Wireless Distribution System (WDS). Unfortunately, most non-AirPort routers are not compatible with Apple's implementation of WDS ... so it very unlikely that your Orange-provided router can be extended wirelessly with the 802.11n AirPort Extreme Base Station (AEBSn).

  • Using my existing email addresses with BT Infinity...

    Hi
    I have 3 different email addresses that I would like to use with with BT infinity.  My current ISP allows me to use their outgoing SMTP server to send mail from these addresses without any 555 or 553 relay errors, nor do they put a signature or 'sent on behalf of' message on my outgoing emails.  Will I be able to do this with BT Infinity?
    Secondly, I travel with a laptop and I'm often connected to hot spots and other people's/companies broadband connection while sending email. To avoid reconfiguring my smtp server depending on who I'm connected to I use a paid for authenticated SMTP service (authsmtp.com). This means I can have a single SMTP setup (mail.authsmtp.com) and send email without problems.  Will BT allow me to connect to mail.authsmtp.com when I'm at home and connected to infinity?
    Thanks

    Its an e-mail issue, not a problem with your actual physical Infinity connection, which you do not have at the moment.
    The e-mail experts are normally on this board.
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • How can i use my existing apple account with the app store when i have no credit card or paypal?

    i dont have a credit card or a paypal account how do i use the bloody appstore when i have neither and already have an apple id?

    This user, mountaingoatgirl, explains how to get a None option in your account details in the iTunes app on a Mac or PC. -
    https://discussions.apple.com/message/24907941

  • TC - using an existing external HD with Data on it

    I just got a TC and I'd like to attach an External HD to it so I can share the files on the HD across the network. (Basically, a NAS).
    The files already on the HD don't show up via sharing when connected to the TC.
    Files I added to the HD while connected to the TC don't show up when the HD is attached to my Mac directly via USB.
    Is there some way to make the same files available regardless of where I attach the drive?
    - Ray

    Yes. Time Machine works better if it is in total control of its storage space.
    Of course partitioning the drive in a Time Capsule is only possible by removing it and doing the partitioning on another computer.
    If this were mine I would get another external drive and connect that to the Time Capsule. Move your data to the new external and allow Time Machine to use the whole internal drive in the Time Capsule instead.
    Allan

  • Using a existing Document type for a new requirement.

    Hi Gurus,
    I have a Sales Documnent type ZOR which was earlier used and now this not being used any more.
    If we start using  the same document type again after changing the description will it have any negative Implications?
    Will any reporting or financial posting or Audit issue occur as we use the existing document type with a new desciption for a new requirement.
    Thanks
    Montee

    Monti,
    1. First you will have to decide that the document you have created for a business process is going to be reappear in future. if not then you can change the document description and reuse it.
    2. Within the document type take care of no. range assignement, Pricing date and billing documents you have assigned (Delivery related or order related)
    3. Item category usage, you would have assigned an item category for this document type check the item category assignement when you are using it for new process relook into into item category details screen. Check even Schedule line category details and its assignement
    4. Check Copy controls once again (Delivery related or order related).
    5. Check the Delivery and billing documents associated with it.
    6. Check its assignement to a specific sales area if configured else OK
    Regards
    Sathya

  • Problem with JNI and Parallel Port dll

    Hi. I'm doing some testes with JNI. Firs i followed the netbeans tutorial for doing a C programa that prints somthing for java.. like.. "Hello java from C".
    So i tried to load a dll from my dll. Like, I have this dll to use the parallel port on windows Xp. So i created a dll to access it an comunicates eoth java.
    I did everything just fine.
    When I start my Java app, the first thing it does is to load this parallel port dll and configure the functions of it.
    After that .. I get this error
    EXCEPTION_FLT_STACK_CHECK (0xc0000092) at pc=0x0093d269, pid=2284, tid=3000
    Can someone explain why ?
    (Sorry if i wasn't clear enough, english is not my native language, so ask if you don't understand something.. )

    hi ,
    I met the same problem this morning, and searched the www.google.com in order to solve it, as a result, your article was shown on my screen. :)
    Till now I have read some technical information and solved my problems. Maybe the solution be useful to you:
    ==============================
    error message : (Environment : Tomcat 5, Windows 2003, Mysql5)
    2006-3-29 11:53:48 org.apache.catalina.core.StandardWrapper unload
    message: Waiting for 2 instance(s) to be deallocated
    ==============================
    cause: the number of connection to database exceeded.another word,too many connections.
    ==============================
    solution: close the connection when it becomes useless for your program. :)
    ==============================
    ps. Sorry for my weak English . hehe ....

Maybe you are looking for