Recent

Author Topic: How to create a linkable .obj file (COFF)?  (Read 44673 times)

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #15 on: February 21, 2011, 02:29:41 am »
If I compile it as an application I'm basically getting the same result regarding dumpbin.
Getting a bit frustrated now...

Could you please provide your whole test project so I can compile exactly the same project as you? Just to make sure that there really aren't any differences in the project settings.
What system did you use to compile it? Could you please also provide that test obj file so I can try dumpbin with it?

Thanks for your time and sticking to my problem. Hopefully we can find a solution in the end...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #16 on: February 21, 2011, 03:42:47 am »
Quote
If I compile it as an application I'm basically getting the same result regarding dumpbin.
Getting a bit frustrated now...
Do you have -Xs switch on? That would erase ALL symbols from the final output.
Quote
Could you please provide your whole test project so I can compile exactly the same project as you?
I didn't do any project, just testing with that unit above.
Quote
What system did you use to compile it? Could you please also provide that test obj file so I can try dumpbin with it?
i386-win32. I can cross-compile to win64 though, maybe I'll do it tonight. I'm on Linux now and my cross compiler is on my Windows (which requires me to reboot) and I need to go out till night.

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #17 on: February 21, 2011, 12:04:45 pm »
I didn't do any project, just testing with that unit above.
How did you compile a unit without any project?  :o
If you're compiling by command line please tell me your command with all the parameters that you use. Thanks.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #18 on: February 21, 2011, 12:49:24 pm »
Quote
How did you compile a unit without any project?
From command line as you've guessed. No additional parameter, just:
Code: [Select]
fpc test.pasIf you want to see the generated assembly (so you can see that the label is there), use -a (or -alnrt for complete information).

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #19 on: March 03, 2011, 04:25:08 pm »
After compiling with the simple command as you suggested no *.obj is created but only an *.o file. Well, I tried with it and interestingly it's a totally different result: While I now get even more "unresolved external symbol" messages, the actual "myfunc" is not listed there anymore. So I assume, this worked.
However, as mentioned I now have a bunch of other messages. I elliminated a part of it by linking setupapi.lib, but there are still some left and I don't know how to solve that:
Code: [Select]
Unit1.o : error LNK2001: unresolved external symbol FPC_PUSHEXCEPTADDR
Unit1.o : error LNK2001: unresolved external symbol FPC_SETJMP
Unit1.o : error LNK2001: unresolved external symbol FPC_POPADDRSTACK
Unit1.o : error LNK2001: unresolved external symbol FPC_CATCHES
Unit1.o : error LNK2001: unresolved external symbol FPC_POPSECONDOBJECTSTACK
Unit1.o : error LNK2001: unresolved external symbol FPC_DESTROYEXCEPTION
Unit1.o : error LNK2001: unresolved external symbol FPC_RERAISE
Unit1.o : error LNK2001: unresolved external symbol FPC_POPOBJECTSTACK

Any idea how to get those symbols to be resolved correctly? I assume there's either some *.lib for that or I have to pass some parameters to the "fpc test.pas" command.
« Last Edit: March 03, 2011, 04:58:45 pm by CodeX »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12641
  • FPC developer.
Re: How to create a linkable .obj file (COFF)?
« Reply #20 on: March 03, 2011, 05:02:21 pm »
After compiling with the simple command as you suggested no *.obj is created but only an *.o file. Well, I tried with it and interestingly it's a totally different result: While I now get even more "unresolved external symbol" messages, the actual "myfunc" is not listed there anymore. So I assume, this worked.
However, as mentioned I now have a bunch of other messages. I elliminated a part of it by linking setupapi.lib, but there are still some left and I don't know how to solve that:
Code: [Select]
Unit1.o : error LNK2001: unresolved external symbol FPC_PUSHEXCEPTADDR
Unit1.o : error LNK2001: unresolved external symbol FPC_SETJMP
Unit1.o : error LNK2001: unresolved external symbol FPC_POPADDRSTACK
Unit1.o : error LNK2001: unresolved external symbol FPC_CATCHES
Unit1.o : error LNK2001: unresolved external symbol FPC_POPSECONDOBJECTSTACK
Unit1.o : error LNK2001: unresolved external symbol FPC_DESTROYEXCEPTION
Unit1.o : error LNK2001: unresolved external symbol FPC_RERAISE
Unit1.o : error LNK2001: unresolved external symbol FPC_POPOBJECTSTACK

Any idea how to get those symbols to be resolved correctly? I assume there's either some *.lib for that or I have to pass some parameters to the "fpc test.pas" command.

See the earlier answer: http://www.lazarus.freepascal.org/index.php/topic,12115.msg61731.html#msg61731

you must also link the objects of all units that you USES (and system is always USES'd), maybe even in the correct order.

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #21 on: March 03, 2011, 05:45:54 pm »
See the earlier answer: http://www.lazarus.freepascal.org/index.php/topic,12115.msg61731.html#msg61731
you must also link the objects of all units that you USES (and system is always USES'd), maybe even in the correct order.
Well, I tried to add the suggested windows.o and objpas.o, but as a result even more "unresolved" messages come up ... while the old ones still remain! So basically I need to know where those FPC_* symbols like FPC_PUSHEXCEPTADDR reside. Apparently not in windows.o and objpas.o

Code: [Select]
Unit1.o : error LNK2001: unresolved external symbol FPC_PUSHEXCEPTADDR
objpas.o : error LNK2001: unresolved external symbol FPC_PUSHEXCEPTADDR
Unit1.o : error LNK2001: unresolved external symbol FPC_SETJMP
objpas.o : error LNK2001: unresolved external symbol FPC_SETJMP
Unit1.o : error LNK2001: unresolved external symbol FPC_POPADDRSTACK
objpas.o : error LNK2001: unresolved external symbol FPC_POPADDRSTACK
Unit1.o : error LNK2001: unresolved external symbol FPC_CATCHES
Unit1.o : error LNK2001: unresolved external symbol FPC_POPSECONDOBJECTSTACK
Unit1.o : error LNK2001: unresolved external symbol FPC_DESTROYEXCEPTION
Unit1.o : error LNK2001: unresolved external symbol FPC_RERAISE
objpas.o : error LNK2001: unresolved external symbol FPC_RERAISE
Unit1.o : error LNK2001: unresolved external symbol FPC_POPOBJECTSTACK
objpas.o : error LNK2001: unresolved external symbol INIT_SYSTEM_LONGINT
objpas.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_LONGINT
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_LONGINT
objpas.o : error LNK2001: unresolved external symbol INIT_SYSTEM_POINTER
objpas.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_POINTER
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_POINTER
objpas.o : error LNK2001: unresolved external symbol INIT_SYSTEM_ANSISTRING
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$file$SHORTSTR
ING
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$file$PCHAR
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$file$CHAR
objpas.o : error LNK2001: unresolved external symbol SYSTEM_CLOSE$file
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$TEXT$SHORTSTR
ING
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$TEXT$PCHAR
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$TEXT$CHAR
objpas.o : error LNK2001: unresolved external symbol SYSTEM_CLOSE$TEXT
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$TYPEDFILE$SHO
RTSTRING
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$TYPEDFILE$PCH
AR
objpas.o : error LNK2001: unresolved external symbol SYSTEM_ASSIGN$TYPEDFILE$CHA
R
objpas.o : error LNK2001: unresolved external symbol SYSTEM_PARAMSTR$LONGINT$$SH
ORTSTRING
objpas.o : error LNK2001: unresolved external symbol fpc_shortstr_to_ansistr
objpas.o : error LNK2001: unresolved external symbol FPC_ANSISTR_DECR_REF
objpas.o : error LNK2001: unresolved external symbol U_SYSTEM_ARGC
objpas.o : error LNK2001: unresolved external symbol U_SYSTEM_ARGV
objpas.o : error LNK2001: unresolved external symbol fpc_ansistr_setlength
objpas.o : error LNK2001: unresolved external symbol fpc_ansistr_unique
objpas.o : error LNK2001: unresolved external symbol SYSTEM_MOVE$formal$formal$I
NT64
windows.o : error LNK2001: unresolved external symbol SYSTEM_MOVE$formal$formal$
INT64
objpas.o : error LNK2001: unresolved external symbol fpc_ansistr_decr_ref
objpas.o : error LNK2001: unresolved external symbol FPC_EMPTYCHAR
objpas.o : error LNK2001: unresolved external symbol FPC_SYS_MKDIR
objpas.o : error LNK2001: unresolved external symbol FPC_SYS_RMDIR
objpas.o : error LNK2001: unresolved external symbol FPC_SYS_CHDIR
objpas.o : error LNK2001: unresolved external symbol FPC_ANSISTR_INCR_REF
objpas.o : error LNK2001: unresolved external symbol FPC_RESOURCESTRINGTABLES
objpas.o : error LNK2001: unresolved external symbol SYSTEM_UPCASE$SHORTSTRING$$
SHORTSTRING
objpas.o : error LNK2001: unresolved external symbol fpc_ansistr_compare_equal
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_LONGWORD
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_SINGLE
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_BYTE
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_WORD
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_PCHAR
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_QWORD
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_INT64
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_SMALLINT
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_LONGBOOL
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_WIDECHAR
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_CHAR
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_BOOLEAN
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_BYTEBOOL
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_TGUID
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_HRESULT
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_PWIDECHAR
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_PWORD
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_PBYTE
windows.o : error LNK2001: unresolved external symbol INIT_SYSTEM_QWORD
windows.o : error LNK2001: unresolved external symbol RTTI_SYSTEM_WORDBOOL
windows.o : error LNK2001: unresolved external symbol INIT_SYSTEM_BYTE
windows.o : error LNK2001: unresolved external symbol SYSTEM_FILLCHAR$formal$INT
64$CHAR
fatal error: 63 unresolved externals

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #22 on: March 03, 2011, 07:50:07 pm »
system.o for sure.

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #23 on: March 03, 2011, 08:01:49 pm »
system.o for sure.
OK, getting closer. Now missing:
Code: [Select]
system.o : error LNK2001: unresolved external symbol SysAllocStringLen
system.o : error LNK2001: unresolved external symbol SysFreeString
system.o : error LNK2001: unresolved external symbol __data_start__
system.o : error LNK2001: unresolved external symbol __data_end__
system.o : error LNK2001: unresolved external symbol SysReAllocStringLen
system.o : error LNK2001: unresolved external symbol INITFINAL
system.o : error LNK2001: unresolved external symbol FPC_THREADVARTABLES
system.o : error LNK2001: unresolved external symbol PASCALMAIN

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #24 on: March 03, 2011, 10:29:07 pm »
I was able to elliminate 3 more missing symbols by including oleaut32.lib from windows sdk.
Now still 5 symbols are left:
Code: [Select]
system.o : error LNK2001: unresolved external symbol __data_start__
system.o : error LNK2001: unresolved external symbol __data_end__
system.o : error LNK2001: unresolved external symbol INITFINAL
system.o : error LNK2001: unresolved external symbol FPC_THREADVARTABLES
system.o : error LNK2001: unresolved external symbol PASCALMAIN
Any idea where to find them?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #25 on: March 04, 2011, 05:24:34 am »
sysinitpas.o

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #26 on: March 04, 2011, 05:53:41 pm »
sysinitpas.o
Strange ... on my x86 system this file exists, but on the x64 system it doesn't. I have the latest daily build installed (Lazarus-0.9.31-29718-fpc-2.4.3-20110304-win64). Going to try to install an older official version...

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #27 on: March 04, 2011, 06:36:13 pm »
Tried three different Lazarus win64 and FPC versions and no sysinitpas.o ... why not?
I see a sysinitpas.pp - can I convert/compile it somehow to an sysinitpas.o? Or can I get an already compiled x64 version of sysinitpas.o somewhere? Or could you upload it please (if you have Win x64)?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to create a linkable .obj file (COFF)?
« Reply #28 on: March 05, 2011, 08:27:57 am »
Hmm... I don't have that either in my x86_64 units. Wait a minute, PASCALMAIN should be defined in a program's object file, not any of the rtl units. Try compiling the FPC code with -a switch and look for PASCALMAIN definition in the generated .s

CodeX

  • New Member
  • *
  • Posts: 24
Re: How to create a linkable .obj file (COFF)?
« Reply #29 on: March 05, 2011, 03:18:34 pm »
The generated .s doesn't contain neither PASCALMAIN nor the other 4 unresolved symbols. It contains a bunch of other stuff, including myfunc as assembler and some EXTRN declarations that are mostly from the included *.lib files and system.o.

 

TinyPortal © 2005-2018