Thread: Unpredictable results with shared library only

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Question Unpredictable results with shared library only

    When compiled as a stand-alone program, my code always behaves as I expect it to.

    However, I've also compiled my code as a shared library. For some reason, calling the library from both Java (using JNI) and Python (using ctypes) gives unpredictable results. In other words, the data I get back from the library is incorrect between 1% and 10% of the time. I can't figure out why this would be since the code being run for both versions is practically identical.

    Does anyone have any ideas as to why this might happen?

    To give you a better picture, I'm compiling the code (for Python) with commands similar to the following:
    Code:
    gcc -c -fPIC -O3 Main.c
    objcopy --input binary --output elf64-x86-64 --binary-architecture i386 prog.dat data.o
    gcc -shared -Wl,-soname,libmain.so -o libmain.so Main.o data.o

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Just a guess - are your SO entry points using the calling convention that JNI and Python expect?

    gg

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    As far as I know, I am using the proper calling conventions for JNI and Python. Although, I would say that there is limited authoritative reference on Python (and I haven't read too much about JNI). I'm not sure if there is some caveat or something that I am missing.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    From the original post it is NOT clear if you tested your program using an C++ main program linking to an C DLL.
    If not, I suggest doing so.

    I am guessing that will test the logic in the DLL to be sure it is correct.

    And, if it works that way; then likely Codepjug's idea of calling convention needs more research to see if it is the cause.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling A Shared library
    By Ectara in forum C Programming
    Replies: 6
    Last Post: 01-18-2010, 04:39 PM
  2. shared library for QNX
    By ReeV in forum C Programming
    Replies: 3
    Last Post: 05-06-2009, 10:58 AM
  3. shared library, but not dynamic !?
    By ccox421 in forum C Programming
    Replies: 11
    Last Post: 03-17-2009, 01:03 PM
  4. error on using shared library
    By -EquinoX- in forum Tech Board
    Replies: 2
    Last Post: 05-06-2008, 04:42 PM
  5. Shared Library
    By Kinasz in forum Linux Programming
    Replies: 5
    Last Post: 10-07-2002, 09:25 AM

Tags for this Thread