Re: Trouble trying to use Shared Libraries with AIX 3.2.5
Posted in 1997
In article <5jsa4c$bom$3@news7.gte.net>, Paul Drake <pdrake1@gte.net> writes > >I think this is a common thing on c compilers (I work on HP-UNIX platform). > I think that the concept of a library (whether shared or static) is that >others are to use these 'common' functions, but these library functions >shouldn't be calling other functions outside of its library (if that could >happen, then if someone wanted to use one of those functions, they couldn't >just link in that library, since they would get "unresolved symbols" of the >function that the library functions call, and then they would have to hunt >down those libraries, maybe guess at which one they're in; it could be a >real mess). > >One way around this is to put all of the functions in one library. For >example, if your library is called lib1.sl, make a lib2.sl with the object >files that contain the functions called from within lib1.sl, and link in >lib1.sl. Then when you make your executable, you just have to link in >lib2.sl. This is what EDA does. When I use EDA in my program, I link in a >shared library. Running Purify against my program, showed that the library >in turn links in at least 8 other libraries. > >If for some reason you absolutely do not want those external functions in a >library, try changing the order of the files (object and library) when >linking. Put the object files/library that call the function first, then >the files that have the function code afterwards. It seems that if the >linker comes across the function code first, it ignores it, since it thinks >it doesn't need it; but if it comes across a call to a function, then it >knows to look out for the code of that function, and will find it if it >hasn't already read the file that contains the function. Sort of...on the command line the library which contains the function MUST be to the right of the library which calls it. E.g. in library lib1.a FUNCTION a(n) DEFINE n INTEGER DEFINE n2 INTEGER IF n < 1 THEN LET n2 = 1 ELSE CALL b(n-1) RETURNING n2 END IF RETURN n*n2 END FUNCTION In lib2.a FUNCTION a(n) DEFINE n INTEGER DEFINE n2 INTEGER IF n < 1 THEN LET n2 = 1 ELSE CALL a(n-2) RETURNING n2 END IF RETURN n*n2 END FUNCTION Since function a in lib1.a calls function 2 in lib2.a we need lib1.a lib2.a on the command line Since function b in lib2.a calls function a in lib1.a we need lib2.a lib1.a on the command line! Solution? Have lib1.a lib2.a lib1.a on the command line. Note you do NOT get duplicatte symbols since the duplicates are 'the same' hence ignored. The actual executable only ever contains one copy of each function. I had this problem on SCO 3.2.4v2 and Pyramid DC/??1X...with 4 libaries (17Mb of libaries were on the link line in total)...to produce a 1.5Mb executable... I could never turn all this into a shared library even with just one shared library and just having main call one function in the shared library... > >Paul -- David Williams