0

I downloaded a free Delphi component for working with BZip2-archives: http://www.torry.net/vcl/compress/other/BZip21.05.zip (More experienced unit AbBzip2.pas component Abbrevia http://sourceforge.net/projects/tpabbrevia/files/) - they are very similar.

The components work well.

Problem:

  1. I see that version *.obj files BZip2 libraries in components - are old - 1.0.5 of 10 December 2007. Decided to update the obj-files into new ones.

  2. I going and download the latest version BZip2 - 1.0.6 - http://www.bzip.org/downloads.html

  3. Unpack the source BZip2 archive into a folder c:\BZip2Src

  4. Run "Open the command line VS2012 x86 Native Tools" (% comspec% / k "" C: \ Program Files (x86) \ Microsoft Visual Studio 11.0 \ VC \ vcvarsall.bat "" x86)

  5. In console, I go to the c:\BZip2Src (Cd /d c:\BZip2Src)

  6. Compile the project as described in the makefile.msc (#usage: nmake.exe -f makefile.msc) and get new *.obj files. Along the way, getting a working programm bzip2.exe.

  7. Copy the new *.obj instead of the old blocksort.obj, huffman.., compress.., decompress.., bzlib.. in folder component for Delphi.

  8. Run Delphi, trying to recompile components.

Get the error "[dcc32 Error] AbBzip2.pas (215): E2065 Unsatisfied forward or external declaration: 'BZ2_hbMakeCodeLengths'" and other similar ones.

or for bzip2.bas - [dcc32 Error] BZip2.pas(171): E2065 Unsatisfied forward or external declaration: '_BZ2_hbMakeCodeLengths'

...
{$L huffman.obj}
{$L compress.obj}
{$L decompress.obj}
{$L bzlib.obj}

{ $L crctable.obj}
{ $L randtable.obj}

{$IFDEF LFS}
uses
  Windows;
{$ENDIF}

procedure _BZ2_hbMakeCodeLengths; external; // **ERROR LINE** 
procedure _BZ2_blockSort; external;  // if i replace on "BZ2_blockSort" (without "_"), i get error "[dcc32 Error] BZip2.pas(710): E2065 Unsatisfied forward or external declaration: 'bz_internal_error'"
procedure _BZ2_hbCreateDecodeTables; external;
...

I can not point out all of the options compiler without any modifications in C++ command line?

Did not work with C + +, help compile correctly *.obj files.

Charles
  • 50,943
  • 13
  • 104
  • 142
Gu.
  • 1,947
  • 4
  • 30
  • 49
  • The simple answer is that you should use the old .obj files. Trying to get this to work with .obj files compiled with `cl` rather than `bcc32` is going to cause you lots of pain. Even when you resolve the references you'll likely have other problems. Why would you want to do that? – David Heffernan Aug 06 '13 at 08:45
  • 1. I want a new version with corrections. 2. I want to learn how to make and attach obj from C++. 3. Earlier work (there are not many differences in the new version zlib2) – Gu. Aug 06 '13 at 08:49
  • I compile a VS. makefile, nmake.exe or cl.exe. Now I tried a BCC32 - other error: [dcc32 Error] BZip2.pas (711): E2065 Unsatisfied forward or external declaration: '__streams' .. '_exit' ... '_fgetc' and ect – Gu. Aug 06 '13 at 09:10
  • ok, i get old version bzip2 (1.0.5) http://archive.ubuntu.com/ubuntu/pool/main/b/bzip2/bzip2_1.0.5.orig.tar.gz, but error not fix :( – Gu. Aug 06 '13 at 09:19
  • Read my answer. The latest Abbrevia ships with 1.0.6. And you have to compile the right way, as is explained in the documentation for Abbrevia. – David Heffernan Aug 06 '13 at 09:20

1 Answers1

3

The Pascal files are designed to be used with .obj files that are compiled in a very specific way. You cannot compile using the bzip2 makefile. You need to compile the files in the specific way that is compatible with the Delphi library.

Take a look at Abbrevia. In the sourceforge repo we have this:

bzip2 SDK v1.0.6

Original download available from http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz

Compile 32-bit with
  bcc32 -q -c -u- -w-8004 -w-8008 -w-8057 -w-8066 -w-8068 -DBZ_NO_STDIO *.c

Compile 64-bit with
  cl -c -nologo -GS- -Z7 -wd4068 -Gs32768 -DBZ_NO_STDIO *.c

So this tells you that 32 bit Abbrevia is designed to be used with bcc32 compiled object files (using that specific command line). Perhaps you can get it to work with cl also. And certainly Craig has managed to do so for his 64 bit builds.

In your question you state that the bzip2 files used in Abbrevia are out of date, and that you want to use 1.0.6. Well, that statement is not true. You've clearly got an out of date version of Abbrevia.

You should pull the latest version of Abbrevia from the sourceforge repo and this comes with .obj files for bzip2 1.0.6. Exactly what you are looking for. If you wish to make some modifications to the bzip2 source code files, you can do so and re-compile them using the command line above.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Yes, it works, thanks. Another little question: what compiler option can remove from obj-file debug text or any garbage (if open any obj i see more text path link "BSC: \ Program Files (x86) \ Embarcadero \ RAD Studio \ 11.0 \ include \ windows \ sdk \ ime_cmodes. h ... ")? for smaler obj-files. – Gu. Aug 06 '13 at 09:28
  • That information is there for a reason. Why would you want to remove it? It does no harm. There's nothing to be gained by removing it. – David Heffernan Aug 06 '13 at 09:31
  • That is, the normal obj and optimization can not be? (similar to delphi = debug dcu) – Gu. Aug 06 '13 at 09:41
  • Clearly the .obj file contains metadata. What is the problem with that? Why do you want to remove it from the .obj file? You aren't going to ship the .obj file. Or are you? – David Heffernan Aug 06 '13 at 09:42
  • it's the size of the application (link my.exe) will be affected? – Gu. Aug 06 '13 at 09:53
  • 1
    The .obj file metadata will all be stripped at the compilation phase. You can readily verify that this is so by looking for the metadata in your executable. – David Heffernan Aug 06 '13 at 09:55
  • 1
    Another shameless plug of an article explaining most of what is discussed here: "Using C object files in Delphi", http://rvelthuis.de/articles/articles-cobjs.html – Rudy Velthuis Aug 06 '13 at 12:34
  • 1
    @RudyVelthuis That article is quite good. But it's a little dated now. Here are the issues that I think is missing: 1. 64 bit 2. Mention of the `Crtl` unit 3. Discussion of COFF and OMF is out-of-date following XE2 release which supports COFF objects 4. Discussion of circular reference issues and how to resolve them (http://stackoverflow.com/questions/4638186/error-while-linking-multiple-c-object-files-in-delphi-2007/4638633#4638633). – David Heffernan Aug 06 '13 at 12:38
  • @DavidHeffernan: Indeed, it is a little outdated WRT Win64 and the other platforms. I already planned to add a section about Win64 and OSX (and perhaps iOS too), as soon as I have a little more time for it. And the (rather new) Crtl unit needs a mention too. I'll take a look at the circular reference problem as well. Thanks for the hints. – Rudy Velthuis Aug 07 '13 at 13:42
  • @Rudy If you all you do re circular ref is point at my linked answer that would be helpful. I've done a lot of this, and experienced circular reference problems very commonly. The trick I came up with is a huge boon! – David Heffernan Aug 07 '13 at 13:43
  • @David: Just did that, thanks. If you see any errors (or other errors), please email me (you can find my email address in the Embarcadero forums). – Rudy Velthuis Aug 07 '13 at 18:35
  • @RudyVelthuis I could not find your e-mail address. Couple of comments though: 1. Probably the best way to get cl is the Platform SDK. 2. cl (at least on x64, but I think full stop) uses different decoration (certainly for `cdecl` functions) without a leading underscore. 3. With cl you need [`/GS-`](http://msdn.microsoft.com/en-us/library/8dbf701c.aspx) to avoid unresolved reference to compiler helper function named, IIRC, `chkstk`. – David Heffernan Aug 07 '13 at 19:08