Thread: Wrong results from dynamic libraries

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    6

    Wrong results from dynamic libraries

    Hello all,

    I am having problems with shared libraries.

    mstrdev@scar:/OS_CHANGES/OS_CHANGES/DIMESERVER/gsoap_2_7/gsoap-2.7.9e/samples/calc_src> ldd test_shift
    libtestlib.so => /home/mstrdev/MSTRPROJ/code_development/external/lib/libtestlib.so (0x00007fd4c977f000)



    test_shift.cpp
    ---------------
    Code:
    main()
    {
    
    s = Function_A(1, 2, 3)
    
    printf("RETURN VALUE IS %d", s);
    
    }
    libtestlib.so
    ------------
    Code:
    int Function_A (int input1, int input2, int input3)
    {
    return 1;
    
    }

    The problem is that "return 1" comes back as -603456842

    Why?

    Is this some kind of strange property with dynamic libraries?
    How can one find out what is going on?

    TIA

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Shared Libraries

    Have you set say LD_LIBRARY_PATH?

    There is also LD_DEBUG to help trace problems (see link)

    How did you create your shared library (gcc -shared)

    Does your program have a prototype for Function_A() in scope?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    Quote Originally Posted by d0mufasa View Post
    Hello all,

    I am having problems with shared libraries.

    mstrdev@scar:/OS_CHANGES/OS_CHANGES/DIMESERVER/gsoap_2_7/gsoap-2.7.9e/samples/calc_src> ldd test_shift
    libtestlib.so => /home/mstrdev/MSTRPROJ/code_development/external/lib/libtestlib.so (0x00007fd4c977f000)



    test_shift.cpp
    ---------------
    Code:
    main()
    {
    
    s = Function_A(1, 2, 3)
    
    printf("RETURN VALUE IS %d", s);
    
    }
    libtestlib.so
    ------------
    Code:
    int Function_A (int input1, int input2, int input3)
    {
    return 1;
    
    }

    The problem is that "return 1" comes back as -603456842

    Why?

    Is this some kind of strange property with dynamic libraries?
    How can one find out what is going on?

    TIA
    your code has nothing to do with a library. You just wrote some function, and then called it in main. Is "function_A" from the lib? Have you declared 's' to be the return type?
    "All that we see or seem
    Is but a dream within a dream." - Poe

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Duplicate threads merged.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    6
    Hello,

    Don't know what is going on here.

    I had changed the programming so that I could pass a value in and that it would hopefully get assigned the correct data.

    I changed it as follows:

    Code:
    main ()
    {
    int returncode;
    
    [snip]
    
    retval = TransHist_Create( merchant_id, &trans_hist_id, transact_id, from_step_id, num_proc, num_succ, num_fail, num_user_err, todays_date, proc_user_id, addendum, getlocalhost(), getpid(), 0, __FILE__, __LINE__, &returncode);
    
    }
    Code:
    Now, in the function : TransHist_Create(...., *returncode)
    {
    ....... [snip] ...
    
    *returncode = 0;
    return 0;
    }
    BUT ..

    in main, the returncode is set to --> 1 <-- ?!?!

    Why??

    I do not understand how return codes can be returned to the caller INCORRECTLY when they are implicitly set to a value in the function.

    The function is in a static library. I got rid of the references to dynamic libraries because of the problems.

    Has anyone seen anything like this? Is it memory corruption or something? How can I find out what is going on?

    TIA

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Linking & Memory usage
    By @nthony in forum C Programming
    Replies: 2
    Last Post: 06-02-2007, 09:57 PM
  2. dynamic libraries
    By kris.c in forum C Programming
    Replies: 9
    Last Post: 01-13-2007, 07:14 AM
  3. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  4. Dynamic Libraries and definition files
    By IconTree in forum Linux Programming
    Replies: 1
    Last Post: 08-10-2005, 01:51 PM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM

Tags for this Thread