Page 1 of 1

Static linked library

Posted: Wed Oct 30, 2013 2:16 am
by spacebuddy
Is there anyway to create a static linked library (.a) or convert a dynamic library (.so) to static in PB x86?

Re: Static linked library

Posted: Thu Oct 31, 2013 1:52 am
by jack
I know how to build a dynamic lib from a static lib but not the other way around, my guess is that it can be done but it's beyond my expertise.
btw you can use otool to view the libraries disassembled, for example, compile this example that's included with PB to dynamic lib.

Code: Select all

Structure MYSTRUCTURE 
  StringVariableA.s 
  StringVariableB.s 
  IntegerVariableA.i 
  FloatVariableA.f 
EndStructure 

ProcedureDLL AttachProcess(Instance) 
  ;this is an array of the structure 
  Global Dim TORETURN.MYSTRUCTURE(300) 
EndProcedure 

ProcedureDLL MyFunction() 
  For x = 0 To 300 
    TORETURN(x)\StringVariableA = "StringA " + Str(x) 
    TORETURN(x)\StringVariableB = "StringB " + Str(x) 
    TORETURN(x)\IntegerVariableA = x 
    TORETURN(x)\FloatVariableA = x + 0.5 
  Next x 

ProcedureReturn @TORETURN() 
EndProcedure
then assuming you named it mydylib you will get mydylib.so, to view the disassembly of the library launch terminal and enter the following
otool -tv mydylib.so
so my guess is that since the library can be disassembled, with enough work one could write a program that would extract the objects and build a static lib.