0

I'm trying to embed a file called window.ui into my C executable, with the goal to access the contents later from within the code:

objcopy --input binary \
        --output elf32-i386 \
        --binary-architecture i386 ../src/window.ui ../window.ui.o

gcc `pkg-config --cflags gtk+-3.0` \
    ../src/*.c \
    ../*.o \
    `pkg-config --libs gtk+-3.0` \
    -o ../a.out

When compiling, GCC fails with the following error:

/usr/bin/x86_64-linux-gnu-ld: i386 architecture of input file `../window.ui.o' is incompatible with i386:x86-64 output
collect2: error: ld returned 1 exit status

Is there any way to force GCC to still include the file?

I've also tried the objcopy with --output elf64-x86-64, and this compiles correctly however the contents are garbled up when reading.


Original guide which inspired me

Henk Schurink
  • 419
  • 6
  • 17
  • How are you creating `window.ui.o`? The linker requires address information to place it in the executable. – Fiddling Bits Aug 10 '18 at 20:49
  • @FiddlingBits I'm creating `window.ui.o` with the `objcopy --input binary --output elf32-i386 --binary-architecture i386 ../src/window.ui ../window.ui.o` command mentioned in the question. – Henk Schurink Aug 10 '18 at 20:51
  • ... what _is_ `window.ui`? I don't get why you're using `objcopy` at all. – TypeIA Aug 10 '18 at 20:52
  • @TypeIA `window.ui` is an XML file with the UI design for Gtk. I'm trying to embed it into the executable because it's needed at runtime. – Henk Schurink Aug 10 '18 at 20:54
  • I see. That's a pretty evil method of embedding a resource. The input files to the linker all have to have the same architecture. Your system is x86_64 and that's what `ld` is trying to produce output for, but you're giving it an `i386` input. Change your `--output` flag to `objcopy` to `x86-64` and you should get better results. – TypeIA Aug 10 '18 at 20:58
  • `objcopy` needs an object file. Are you just adding `.o` to the end of `window.ui`? – Fiddling Bits Aug 10 '18 at 20:58
  • @TypeIA `--output x86-64` is not available on my system, but I think you mean `elf64-x86-64`? Unfortunately it compiles but the XML content is scrambled and garbled upon reading (for example: `` becomes ` – Henk Schurink Aug 10 '18 at 22:46

1 Answers1

0

"solved" by using gnu-ld instead:

ld -r -b binary ../src/window.ui -o ../window.ui.o

Couldn't figure out why objcopy didn't work though.

Henk Schurink
  • 419
  • 6
  • 17