0

I am working on one migration project from x32 bit to x64. Here I am using this code:

{$L com_1.obj}
{$L com_is1.obj}
{$L com_2.obj}

But while compiling code I am getting error as

[dcc64 Error] XXX.dpr(919): E2045 Bad object file format: 'E:\MyProj\com_sha.obj'

I am not able to trace why it is happening.

Is it due to 32 bit obj file used for compiling x64 bit delphi project?

If it is I have also tried to create a obj file with x64 bit environment.

Can anyone please help me on this?

I am using Delphi 10 Seattle.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
A B
  • 1,461
  • 2
  • 19
  • 54
  • Shameless plug of my article: http://rvelthuis.de/articles/articles-cobjs.html That should explain it. And no, you can't use 32 bit obj files in a 64 bit program. The article also shows how to handle the unsatisfied forwards. – Rudy Velthuis May 17 '17 at 08:36
  • 1
    FWIW, try to add the unit System.Win.Crtl (Note: C-R-T-L, not C-T-R-L) to your code. That should take care of many of the unsatisfied forwards. – Rudy Velthuis May 17 '17 at 08:43
  • This is my next question http://stackoverflow.com/q/44020038/3110262 – A B May 17 '17 at 08:54

2 Answers2

3

You cannot use a 32 bit object with the 64 bit compiler. You must recompile your code with a 64 bit compiler.

You can use a number of different compilers to do this. Although I have heard of people succeeding with gcc I have never managed to do that. I believe that the modern Clang based Embarcadero compiler can be used, but I personally have no experience of that. I have always used the Microsoft compiler to create 64 bit objects. And certainly this is how Embarcadero themselves have done it for libraries like zlib that they link to their RTL.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I have created a 64 bit obj file using Visual C++ Express. But no luck. I am getting the same error for the obj file. – A B May 17 '17 at 06:53
  • Clearly you have some wrong objects lying around. Note that the error that is reported is for an object not in your list. Go back to basics. Prove to yourself that you can link to a simple function that adds two int values and returns the result. Work up from there. This is debugging 101. Simplify to a problem you can understand. Then apply to the real, more complex problem. – David Heffernan May 17 '17 at 07:01
  • That's a different question. I do know how to deal with those issues though. But not at this question. – David Heffernan May 17 '17 at 08:33
  • Do not compile the files as C++ object files. Try to compile them as C object files. And what format are these object files? There exist several incompatible formats. – Rudy Velthuis May 17 '17 at 08:38
  • @Rudy No, that's not it. Stack checking can be suppressed with a compiler switch. And the presence of `__imp_XXX` implies compilation with runtime linking. My guess is that asker is doing all this in the VS GUI rather than getting to grips with `cl`. My command line to `cl` looks like this: `cmd = '"%(cl)s" /I "%(include)s" /c /wd4090 /wd4700 /O2 /GS- /Gs131072 /Fo%(outdir)s/ %(cmd)s' % locals()` Obviously that's Python code with some subsitutions but you should be able to get the drift. – David Heffernan May 17 '17 at 08:40
  • @David: What stack checking do you mean? – Rudy Velthuis May 17 '17 at 08:50
  • I have created one more question for next query: http://stackoverflow.com/q/44020038/3110262 – A B May 17 '17 at 08:55
  • @RudyVelthuis `__GSHandlerCheck`. As you state in your article, you've not done much with x64 objects. There's quite a bit missing from that article in that regard. – David Heffernan May 17 '17 at 09:00
2

Yes you need to convert those .obj files to 64 bit.

Converting 32-bit Delphi Applications to 64-bit Windows states:

  • 64-bit External .obj Files: If you expect your 64-bit Windows application to link to an external .obj file, keep in mind that you will need a 64-bit version of the .obj file to link with a 64-bit Windows application.
LU RD
  • 34,438
  • 5
  • 88
  • 296
  • As said in both my and @David's answer, use a 64-bit compiler to create a 64-bit .obj file. – LU RD Jul 20 '19 at 17:56