Using a shared library on AIX -- works in a C program, doesn't work in a Progress program - Forum - OpenEdge Development - Progress Community

Using a shared library on AIX -- works in a C program, doesn't work in a Progress program

 Forum

Using a shared library on AIX -- works in a C program, doesn't work in a Progress program

This question is not answered

Man, IBM’s XL C compiler doesn’t seem to like Progress.
 
I got this as factorial.p
 
procedure factorial external "/home/sauge/c/factorial.so"  cdecl  :
 
  define input parameter n as short.
  define return parameter f as short.
 
end.  /* shared library */
 
 
 
define variable Result as integer no-undo.
 
run factorial (4, output Result).
 
disp Result.   /* should be 4 * 3 * 2 * 1 */
 
 
and my factorial is this:
 
int factorial(int n)
{
 
  if (n == 0) return 1;
 
  return n * factorial(n - 1);
 
}
 
And compiled that into /home/sauge/c/factorial.so.
 
My pro is this:
 
 
#!/bin/bash                     
                                 
export LIBPATH=/home/sauge/c    
                                 
/var/dlc/bin/pro                
 
 
The LIBPATH and absolute path in the procedure should say use /home/sauge/c/factorial.so right?
 
 
Ran my ./pro and got this:
 


 
 
So after a WTF I wrote a runner that will load in the .so and run the program from there like Progress should.  Here is run.c:
 
 
    #include <stdlib.h>
    #include <stdio.h>
    #include <dlfcn.h>
 
    int main(int argc, char **argv) {
        void *handle;
        int (*factorial)(int);
        char *error;
 
        handle = dlopen ("/home/sauge/c/factorial.so", RTLD_LAZY);
        if (!handle) {
            fputs (dlerror(), stderr);
            exit(1);
        }
 
        factorial = (int(*)(int)) dlsym(handle, "factorial");
        if ((error = dlerror()) != NULL)  {
            fputs(error, stderr);
            exit(1);
        }
 
        printf ("Factorial is %d\n", (*factorial)(4));
        dlclose(handle);
    }
 
And ran it:
 
:c $ ./run                
Factorial is 24           
 
Works.
 
So… Grrrrrr
 
All I can think is that Progress is linked with a different version of a dynamic link loader library and is confused???
 
Here are the build instructions:
 
:c $ cat makefile                                                              
all: factorial.c                                                               
        cc -c factorial.c                                                      
        cc -bE:factorial.exp -bM:SRE -bnoentry -o factorial.so factorial.o     
                                                                                
run: run.c                                                                      
        cc -o run run.c -L:/home/sauge/c factorial.so -bnoquiet                
 
and the symbols
 
:c $ cat factorial.exp     
factorial                  
 
Anyone spot what is going on?

Scott Augé
President
Amduus Information Works, Inc.
Technical Services for Business and Government
http://www.amduus.com/cms

All Replies
  • Just for kicks, does your new exe have the same permissions/ownership as $DLC/bin/_progres? _progres is owned by root, typically, and has setuid permission. This affects the dynamic loader on various platforms. IIRC, some platforms will only load from /usr/lib under those circumstances, ignoring the library path env var. That might be worth taking a look at.