Recent

Author Topic: Static linking  (Read 36301 times)

herux

  • Full Member
  • ***
  • Posts: 102
Re: Static linking
« Reply #15 on: January 18, 2012, 03:06:08 am »
Hi all

I really like this thread. contains a lot of expert knowledge
 :)

eMko

  • New Member
  • *
  • Posts: 13
Re: Static linking
« Reply #16 on: October 13, 2012, 10:48:49 pm »
Good one :) . Shame I could not find it by google just a few days ago  :'(

I had to do an extension to Firefox (also to Chrome and IE - but that's different story) - toolbar which displays some data from university information system (unread mails, exam dates, project deadlines...). Since our information system is proprietary (we actively develop it and sell it to universities), we didn't like the possibility to write the communication code in javascript - XPI file is just renamed zip (all metadata are in files in the archive), so anyone can unzip the firefox extensions and read the sources. FF extensions are able to call external shared libraries packed into the xpi, but there are problems with dependencies - the dll/so should be self-contained or you can get random funny errors.

If I had known how to statically link openssl library into pascal dll, I wouldn't have written that library in C++, the language I totally hate. (Ok, situation is not so bad with boost library, but still... :-/ ).

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Static linking
« Reply #17 on: October 15, 2012, 02:42:51 pm »
To take this opportunity of being reminded of this thread, just to check if you, Ludo, added that info to the wiki? If not, I would do it...
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Static linking
« Reply #18 on: October 15, 2012, 05:08:03 pm »
No, I didn't  ;)

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Static linking
« Reply #19 on: October 15, 2012, 09:26:35 pm »
Ok then I'll do it... unless you do it before ;)
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Static linking
« Reply #20 on: November 20, 2018, 07:41:38 pm »
Hi,

I'm trying to link statically mpg123 lib in 64-bit, Windows.

I already linked libkernel32.a, libm.a, libmsvcrt.a, libgcc.a

But I still see several errors while linking:

Undefined symbol: sqrt (cos, sin, pow, log, lseek64)

What .a files from MinGW64 are responsible for these functions?

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Static linking
« Reply #21 on: November 20, 2018, 08:21:34 pm »
You can add this file into your project:

https://github.com/BeRo1985/pasvulkan/blob/master/src/PasVulkan.StaticLinking.pas

It will provide the necessary functions for static linking.

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Static linking
« Reply #22 on: November 21, 2018, 11:56:07 am »
Hi,

Thanks for your advice!

Regrettably this .pas code doesn't work.

I get several linking errors. For example:

undefined symbol: fseek

I found fseek(), but it's linked from some lib?

function fseek(s:pointer;offset:int64;whence:longint):longint; cdecl; external name 'fseek';
« Last Edit: November 21, 2018, 12:42:34 pm by Igor Kokarev »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Static linking
« Reply #23 on: November 21, 2018, 01:23:07 pm »
Well, I have never used the file from Bero. So I do not have any real world experience with it. But I do a lot of static linking with sqlite3, used by the mORMot.

Perhaps you can have a look at it:
https://github.com/synopse/mORMot/blob/master/SynSQLite3Static.pas

This surely works on many systems.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Static linking
« Reply #24 on: November 21, 2018, 01:34:27 pm »
It reads if he wants to link the sourcecode (pas).......
Specialize a type, not a var.

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Static linking
« Reply #25 on: November 21, 2018, 04:08:26 pm »
I successfully linked statically mpg123.

I compiled mpg123 lib in MSYS2/MinGW64

then I copied a series of .a and .o files from mpg123 and from MingGW64.

Decoding of MP3 works fine.

Currently I'm trying to optimize a number of used .a and o. files - probably I can implement Pascal version of some C functions.

And also I'm looking for a way to disable debug messages in console from mpg123.

I didn't know how to implement Pascal version of mingw_vfprintf() and lseek64() so I added a dummy functions. I know it's not correct.

Code: Pascal  [Select][+][-]
  1. {$linklib Libs64\libmsvcrt.a}
  2. {$linklib Libs64\libkernel32.a}
  3. {$linklib Libs64\libgcc.a}
  4. {$linklib Libs64\libshlwapi.a}
  5.  
  6. {$L Libs64\compat.o}
  7. {$L Libs64\compat_str.o}
  8.  
  9. {$L Libs64\dct36_avx.o}
  10. {$L Libs64\dct36_x86_64.o}
  11. {$L Libs64\dct64.o}
  12. {$L Libs64\dct64_avx.o}
  13. {$L Libs64\dct64_avx_float.o}
  14. {$L Libs64\dct64_x86_64.o}
  15. {$L Libs64\dct64_x86_64_float.o}
  16. {$L Libs64\dither.o}
  17. {$L Libs64\equalizer.o}
  18. {$L Libs64\feature.o}
  19. {$L Libs64\format.o}
  20. {$L Libs64\frame.o}
  21. {$L Libs64\getcpuflags_x86_64.o}
  22. {$L Libs64\icy.o}
  23. {$L Libs64\icy2utf8.o}
  24. {$L Libs64\id3.o}
  25. {$L Libs64\index.o}
  26. {$L Libs64\layer1.o}
  27. {$L Libs64\layer2.o}
  28. {$L Libs64\layer3.o}
  29. {$L Libs64\lfs_alias.o}
  30. {$L Libs64\lfs_wrap.o}
  31. {$L Libs64\libmpg123.o}
  32. {$L Libs64\ntom.o}
  33. {$L Libs64\optimize.o}
  34. {$L Libs64\parse.o}
  35. {$L Libs64\readers.o}
  36. {$L Libs64\stringbuf.o}
  37. {$L Libs64\synth.o}
  38. {$L Libs64\synth_8bit.o}
  39. {$L Libs64\synth_real.o}
  40. {$L Libs64\synth_s32.o}
  41. {$L Libs64\synth_stereo_avx.o}
  42. {$L Libs64\synth_stereo_avx_float.o}
  43. {$L Libs64\synth_stereo_avx_s32.o}
  44. {$L Libs64\synth_stereo_x86_64.o}
  45. {$L Libs64\synth_stereo_x86_64_float.o}
  46. {$L Libs64\synth_stereo_x86_64_s32.o}
  47. {$L Libs64\synth_x86_64.o}
  48. {$L Libs64\synth_x86_64_float.o}
  49. {$L Libs64\synth_x86_64_s32.o}
  50. {$L Libs64\tabinit.o}
  51.  

Code: Pascal  [Select][+][-]
  1. unit StaticLinkingUtils;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Math;
  9.  
  10. function _log(x: double): double; cdecl;
  11. function _sqrt(x: double): double; cdecl;
  12. function _sin(x: double): double; cdecl;
  13. function _cos(x: double): double; cdecl;
  14. function _pow(x,y: double): double; cdecl;
  15. function _lseek64(ahandle: Pointer; offset: Integer; whence: Integer): Integer; cdecl;
  16. function int_mingw_vfprintf(): Integer; cdecl;
  17.  
  18.  
  19. implementation
  20.  
  21.  
  22. function _log(x: double): double; cdecl; [alias: 'log'];
  23. begin
  24.   result := 0; // ln(x);
  25. end;
  26.  
  27. function _sqrt(x: double): double; cdecl; [alias: 'sqrt'];
  28. begin
  29.   result := sqrt(x);
  30. end;
  31.  
  32. function _sin(x: double): double; cdecl; [alias: 'sin'];
  33. begin
  34.   result := sin(x);
  35. end;
  36.  
  37. function _cos(x: double): double; cdecl; [alias: 'cos'];
  38. begin
  39.   result := cos(x);
  40. end;
  41.  
  42. function _pow(x,y: double): double; cdecl; [alias: 'pow'];
  43. begin
  44.   result := power(x,y);
  45. end;
  46.  
  47. function _lseek64(ahandle: Pointer; offset: Integer; whence: Integer): Integer; cdecl; [alias: 'lseek64'];
  48. begin
  49.   Result:=0;
  50. end;
  51.  
  52. function int_mingw_vfprintf(): Integer; cdecl; [alias: '__mingw_vfprintf'];
  53. begin
  54.   Result:=0;
  55. end;
  56.  
  57. end.
  58.  
« Last Edit: November 21, 2018, 04:09:58 pm by Igor Kokarev »

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Static linking
« Reply #26 on: November 24, 2018, 05:09:45 pm »
mpg123 with static linking freezes frequently on half of MP3 files.

Same code with compiled (by me) DLL works fine.

Any advices?
« Last Edit: November 24, 2018, 05:24:55 pm by Igor Kokarev »

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Static linking
« Reply #27 on: November 26, 2018, 06:47:37 pm »
The problem was in a conflict of functions for mpg123 and zlib. Some global cdecl functions were linked from .a libs and same functions were implemented in Pascal code. So it didn't worked stable.

I have to be careful when use global cdecl functions in different statically linked C libraries.

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Static linking
« Reply #28 on: December 04, 2018, 08:02:19 am »
Can you help me implement in Pascal __ms_vsnprintf() for static linking:

From stdio.h in MinGW64:

Code: Pascal  [Select][+][-]
  1. # undef vsnprintf
  2.   __attribute__((__format__ (ms_printf, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
  3.   int __cdecl __ms_vsnprintf(char * __restrict__ d,size_t n,const char * __restrict__ format,va_list arg)
  4.     __MINGW_ATTRIB_DEPRECATED_MSVC2005 __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
  5.  
  6.   __mingw_ovr
  7.   __attribute__((__format__ (ms_printf, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
  8.   int vsnprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, va_list __local_argv)
  9.   {
  10.     return __ms_vsnprintf (__stream, __n, __format, __local_argv);
  11.   }
  12.  
  13.   __attribute__((__format__ (ms_printf, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
  14.   int __cdecl __ms_snprintf(char * __restrict__ s, size_t n, const char * __restrict__  format, ...);
  15.  



 

TinyPortal © 2005-2018