Recent

Author Topic: Convert Delphi Package that uses C .obj files?  (Read 7082 times)

snorkel

  • Hero Member
  • *****
  • Posts: 796
Convert Delphi Package that uses C .obj files?
« on: November 09, 2015, 06:24:24 pm »
I have a older Delphi component package from Delphi 6 and I got it to compile, but it won't link as it uses several C .obj files compiled with C++ builder.

Is there anyway to recompile those c files if the source is available so they can work with Lazarus?
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: Convert Delphi Package that uses C .obj files?
« Reply #1 on: November 09, 2015, 07:05:16 pm »
I have a older Delphi component package from Delphi 6 and I got it to compile, but it won't link as it uses several C .obj files compiled with C++ builder.

Is there anyway to recompile those c files if the source is available so they can work with Lazarus?
yes fpc can statically link what ever the mingw gcc compiles.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

snorkel

  • Hero Member
  • *****
  • Posts: 796
Re: Convert Delphi Package that uses C .obj files?
« Reply #2 on: November 09, 2015, 09:19:49 pm »
So the only issue may be whether or not mingw will have issues with the C++ builder source.
The component docs say it's C code so I guess that should work.

The current obj files raise this error when linking:

lazarus.pp(142,1) Error: Illegal COFF Magic while reading C:\Users\snorkel\Documents\laz_components\Envision\Trees.Obj
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

Cyrax

  • Hero Member
  • *****
  • Posts: 758
Re: Convert Delphi Package that uses C .obj files?
« Reply #3 on: November 10, 2015, 12:58:14 am »
FPC doesn't support OMF object format which is used in (Turbo) C++ Builder. If you don't have source files for those .obj files, there isn't much to be done.

parcel

  • Full Member
  • ***
  • Posts: 135
Re: Convert Delphi Package that uses C .obj files?
« Reply #4 on: November 10, 2015, 01:25:44 am »
I'm using TDM-GCC with C sources in the past.

In opensource Imgaginlib, tiff support with compiled OBJ files, It works.

zlib in Imaginglib like this,

Code: Pascal  [Select]
  1. unit ZLibDelphi;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. const
  9.  
  10.   {$ifdef FPC}
  11.   ZLIB_VERSION = '1.2.8';
  12.   {$else}
  13.   ZLIB_VERSION = '1.2.1';
  14.   {$endif}
  15.  
  16.   Z_NO_FLUSH = 0;
  17.   Z_FINISH = 4;
  18.  
  19.   Z_OK = 0;
  20.   Z_STREAM_END = 1;
  21.  
  22. type
  23.  
  24.   PRZStream = ^RZStream;
  25.  
  26.   RZStream = record
  27.     NextIn: PByte;
  28.     AvailIn: Cardinal;
  29.     TotalIn: Cardinal;
  30.     NextOut: PByte;
  31.     AvailOut: Cardinal;
  32.     TotalOut: Cardinal;
  33.     Msg: PAnsiChar;
  34.     State: Pointer;
  35.     AllocFunc: Pointer;
  36.     FreeFunc: Pointer;
  37.     Opaque: Cardinal;
  38.     DataType: Integer;
  39.     Adler: Cardinal;
  40.     Reserved: Cardinal;
  41.   end;
  42.  
  43. function  inflateInit_(strm: Pointer; version: Pointer; stream_size: Integer): Integer; cdecl; external;
  44. function  inflateReset(strm: Pointer): Integer; cdecl; external;
  45. function  inflate(strm: Pointer; flush: Integer): Integer; cdecl; external;
  46. function  inflateSync(strm: Pointer): Integer; cdecl; external;
  47. function  deflateInit(strm: Pointer; level: Integer): Integer;
  48. function  deflateInit_(strm: Pointer; level: Integer; version: Pointer; stream_size: Integer): Integer; cdecl; external;
  49. function  deflateReset(strm: Pointer): Integer; cdecl; external;
  50. function  deflate(strm: Pointer; flush: Integer): Integer; cdecl; external;
  51. function  deflateEnd(strm: Pointer): Integer; cdecl; external;
  52. function  inflateEnd(strm: Pointer): Integer; cdecl; external;
  53. function  deflateParams(strm: Pointer; level: Integer; strategy: Integer): Integer; cdecl; external;
  54.  
  55. implementation
  56.  
  57. uses
  58.   LibDelphi;
  59.  
  60. function deflateInit(strm: Pointer; level: Integer): Integer;
  61. begin
  62.   Result:=deflateInit_(strm,level,PAnsiChar(ZLIB_VERSION),SizeOf(RZStream));
  63. end;
  64.  
  65. {$ifdef FPC}
  66. {$ifndef CPUX86_64}{$L Compiled\inflate.o}{$else}{$L Compiled\x64\inflate.o}{$endif}
  67. {$ifndef CPUX86_64}{$L Compiled\crc32.o}{$else}{$L Compiled\x64\crc32.o}{$endif}
  68. {$ifndef CPUX86_64}{$L Compiled\adler32.o}{$else}{$L Compiled\x64\adler32.o}{$endif}
  69. {$ifndef CPUX86_64}{$L Compiled\inftrees.o}{$else}{$L Compiled\x64\inftrees.o}{$endif}
  70. {$ifndef CPUX86_64}{$L Compiled\inffast.o}{$else}{$L Compiled\x64\inffast.o}{$endif}
  71. {$ifndef CPUX86_64}{$L Compiled\deflate.o}{$else}{$L Compiled\x64\deflate.o}{$endif}
  72. {$ifndef CPUX86_64}{$L Compiled\zutil.o}{$else}{$L Compiled\x64\zutil.o}{$endif}
  73. {$ifndef CPUX86_64}{$L Compiled\trees.o}{$else}{$L Compiled\x64\trees.o}{$endif}
  74. {$ifndef CPUX86_64}{$L Compiled\compress.o}{$else}{$L Compiled\x64\compress.o}{$endif}
  75. {$ifndef CPUX86_64}{$L Compiled\uncompr.o}{$else}{$L Compiled\x64\uncompr.o}{$endif}
  76. {$else}
  77. {$L Compiled\inflate.obj}
  78. {$L Compiled\crc32.obj}
  79. {$L Compiled\adler32.obj}
  80. {$L Compiled\inftrees.obj}
  81. {$L Compiled\inffast.obj}
  82. {$L Compiled\deflate.obj}
  83. {$L Compiled\zutil.obj}
  84. {$L Compiled\trees.obj}
  85. {$L Compiled\compress.obj}
  86. {$L Compiled\uncompr.obj}
  87. {$endif}
  88.  
  89. end.
  90.  

also need libdelphi.pas in attachment.

but it's not good idea, sometimes conflict with other lib linked other parts. cannot find local 'C' proxy functions(malloc, free and so on) in unit definition. when it's defined global, sometimes conflict with other library functions, but delphi is not.

And other example is pcre.
« Last Edit: November 10, 2015, 01:36:41 am by parcel »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Convert Delphi Package that uses C .obj files?
« Reply #5 on: November 10, 2015, 04:00:03 am »
Try Agner's ObjConv:
Quote
This utility can be used for converting object files between COFF/PE, OMF, ELF and Mach-O formats for all 32-bit and 64-bit x86 platforms.....
...
last modified: 2015-Oct-15.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7497
Re: Convert Delphi Package that uses C .obj files?
« Reply #6 on: November 10, 2015, 10:09:42 am »
BCB builder used to come with an OMF<->COFF tool iirc