0

I have a library that basically implements a print and I have an object file in 32-bits and I want to create an object file with the print library and link them together. The problem is whenever I try to create a 32-bit. Am I missing something?

I've tried compiling using gcc -m32 -o print.o print.c and now tried gcc -m32 -ffreestanding -nostdlib -o print.o -c print.c but if i remove the -m32 flag it works but it generates a 64 bit file

but for some reason I get this error:

In file included from print.c:2:
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
   27 | #include <bits/libc-header-start.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Program:

#include <stdio.h>

void PRINT(int num)
{
    printf("%d\n",num);
}
Martimc.
  • 53
  • 1
  • 6
  • On the face of it, your compiler (or, more accurately, the supporting libraries and headers) are not installed correctly. If you omit the `-m32`, do you get a different result? – Jonathan Leffler Jun 12 '22 at 16:03
  • 2
    This sometimes happens when you don't have the 32bit headers installed. – vmemmap Jun 12 '22 at 16:22
  • 1
    yeah i needed to do sudo apt-get install gcc-multilib and it works now, thanks a lot – Martimc. Jun 12 '22 at 16:24
  • Apart from missing gcc-multilib, `-ffreestanding` seems unlikely to work with `stdio.h` and its functions. Also, `gcc -m32 -o print.o print.c` is missing a `-c`, so you're actually linking an executable called `print.o`. – Peter Cordes Jun 12 '22 at 22:07

0 Answers0