-1

how to can i achieve linking 2 .o file without CRT.

Compiling .c files:

gcc -ffreestanding -c file.c -o file.o

Linking:

gcc  file1.o file2.o -o f.o

Flags -nostartfiles and -nostdlib don't help me.

Vitaliy
  • 7
  • 2
  • 3
    Your "linking" is not the gcc command line used to produce an object file... You need to expand your question to describe what your desired outcome is. Another object file? A static library? A shared object? An executable? ELF format? a.out format? PE format? raw binary? Then with your attempt, describe what actually happened and what needs to be different. – Ben Voigt Feb 14 '19 at 20:30
  • 1
    Possibly https://stackoverflow.com/questions/2980102/combine-two-gcc-compiled-o-object-files-into-a-third-o-file –  Feb 14 '19 at 20:39
  • @BenVoigt I just compile 2 .c file and i want to link their in 1 object file.I am writing a operating system, i want to link my kernel with another C file that contain some functions and than link it with bootloader,but my kernel is linked with CTR, hence it does nor work properly. – Vitaliy Feb 14 '19 at 20:41
  • 1
    But why do you think you need intermediate merged object files? You can pass all the objects in the final link step, the one creating the fully resolved executable. If you don't want to keep track of all the object files, that's what a static library is for. – Ben Voigt Feb 14 '19 at 20:46
  • @BenVoigt I need to get .bin file in the final, by way linking bootloader with kernel,but before that i need link kernel fro several files, in the step kernel is linked with CRT too, that don't need. – Vitaliy Feb 14 '19 at 20:56
  • You haven't answered the question, @Vitaliy, just rephrased your previous assertion. If indeed you need to make a single executable serving as both bootloader and kernel (dubious), then why do you need to link the object files contributing to those logical components into intermediate files before linking everything together into a final executable? – John Bollinger Feb 14 '19 at 21:03
  • Alternatively, have you considered that what you want to do in creating a single file containing both a bootloader and a kernel may be a different thing than what the rest of us call "linking"? – John Bollinger Feb 14 '19 at 21:05

1 Answers1

0

I just compile 2 .c file and i want to link their in 1 object file

ld -r -o f.o file1.o file2.o
Employed Russian
  • 199,314
  • 34
  • 295
  • 362