What exactly is the o. file? lazarus / 12-Debugger ---------------------------------------------------------------------- Danail · 2007-03-21 13:26 So? ---------------------------------------------------------------------- Marc · 2007-03-21 13:45 a .o file is a so called object file. This file contains compiled code. FPC compiles every unit into a .o (and a .ppu, containing info needed for fpc). After compilation, all .o files get linked together through a linker (ld or the internal linker) into a executable. ---------------------------------------------------------------------- Danail · 2007-03-22 15:31 Then can I use a the o. file of some of my units in another program. If I can, then how? ---------------------------------------------------------------------- abb · 2007-03-22 18:08 Quote from: "Danail"Then can I use a the o. file of some of my units in another program. If I can, then how? I'd look at the compiler directives. Borland pascal compilers have {$L} directive for object files linking. Hope Free Pascal also has similar directive. Please take a look at the docs. HTH! ---------------------------------------------------------------------- Danail · 2007-03-23 13:01 I used the {$L} option and the program compiled successfuly, so it is supported. However it remained to me unclear how to use the functions and the procedures there (in the linked o. file). Trying to call them provokes error. ---------------------------------------------------------------------- Bart · 2007-03-23 14:50 Did you declare the functions you want to use from the .o file like Code: [Select]{$L someunit.o} procedure foo; external; This is the old TP style of linking in external object files. Bart ---------------------------------------------------------------------- Marc · 2007-03-23 16:25 And now the question..... Why do you want to do this ? ---------------------------------------------------------------------- Danail · 2007-03-23 19:48 It has many advantages. Now I can think out for two: you can use units without revealing your code; use code compiled with GCC and other languages creating o. files without even knowing the language that they are made. ---------------------------------------------------------------------- abb · 2007-03-24 11:52 Quote from: "Danail"I used the {$L} option and the program compiled successfuly, so it is supported. However it remained to me unclear how to use the functions and the procedures there (in the linked o. file). Trying to call them provokes error. Do you know the calling model type of your external procedure? May be it it is a C procedure? It's worth to know it. ---------------------------------------------------------------------- Danail · 2007-03-24 19:39 Er... by the way does anyone know a java compiler that makes o. files? ---------------------------------------------------------------------- abb · 2007-03-25 18:37 Quote from: "Danail"Er... by the way does anyone know a java compiler that makes o. files? Offtopic.... Java COMPILER??? Java is not a compiler. It works a p-code, which Java RTE interpets and executes. This is the reason why Java is platform- independent. ---------------------------------------------------------------------- felipemdc · 2007-03-25 20:11 If you want to convert java code to .o files, I would say you shouldn't be using Java in the first place. ---------------------------------------------------------------------- Marc · 2007-03-26 09:46 Bewarned that you cannot export any class, ansistring or dynarray this way. ---------------------------------------------------------------------- Danail · 2007-03-28 09:00 If the o. file is a readily compiled output, so it is supposed to be a platform dependant. So o. file compiled for windows may not be useful on Linux, Is it right? ---------------------------------------------------------------------- felipemdc · 2007-03-28 11:39 Quote from: "Danail"If the o. file is a readily compiled output, so it is supposed to be a platform dependant. So o. file compiled for windows may not be useful on Linux, Is it right? Yes, exactly. ---------------------------------------------------------------------- Danail · 2007-03-29 08:21 Can I find somewhere information about the structure of the o. file?  I also want to also how is generated the o. file from Lazarus - directly from the pascal code, or there is another file or files, that apear before the o. file. ---------------------------------------------------------------------- felipemdc · 2007-03-29 10:04 Quote from: "Danail"Can I find somewhere information about the structure of the o. file? google for object file format, coff or similar things Quote I also want to also how is generated the o. file from Lazarus - directly from the pascal code, or there is another file or files, that apear before the o. file. The compiler transforms pascal code into assembler, and later transforms the assembler into object code (in object files). On many platforms fpc uses by default it´s internal assembler, then there are no intermediary files. If you use a external assembler (like gnu as), then we have a intermediary assembler file. Note that I´m not exactly sure about this. Maybe fpc has an way to feed the assembler to gas that doesn´t require a intermediary file. I wouldn´t know. I know it´s possible to ask fpc to generate asm files. Anyway, the basic idea is: pascal --> assembler --> machine code ---------------------------------------------------------------------- Marc · 2007-03-29 11:37 IIRC fpc used to have an option to pass assembler by pipes, but its gone now. With the current releases, on most platforms you can choose to use the internal or external assembler. By choosing the external assembler you also get the .s (asm) file. ---------------------------------------------------------------------- Danail · 2007-03-29 17:51 How to choose the external assembler? ---------------------------------------------------------------------- felipemdc · 2007-03-29 18:24 type fpc on the command line. It will give a list of possible options. It´s one of the first ones. on windows you may need to type the full path to fpc.exe There is also a list here: http://www.freepascal.org/docs-html/user/userse16.html#x33-400005.1