C.Unbay
C.Unbay

Reputation: 2826

Objcopy getting object file 64 bit binaries

I use objcopy on windows 10 to embed my dll inside an exe and load it. It runs fine with 32 bit compilation with a 32 bits binary dll file as i am getting no errors loading my dll.

objcopy --prefix-symbol=_ --input-target binary --output-target pe-i386 --binary-architecture i386 somedll.dll somedll.o

How can I set objcopy arguments so that I can get a 64 bit binaries object file? If it is not possible with objcopy is there any alternatives to it ? My dll doesnt get loaded when i compile it to be 64 bits, and if i try to compile the executable with the object file as in 64 bits it returns error saying that my object file is not compatible with 64 bit compilation.

so during gcc compilation for example, i have to do

gcc -m32 Myfile.c somedll.o -o output.exe

if i remove -m32 it doesnt compile because somedll.o is set to 32 bits even if it was 64 bits as in dll, so thats why my LoadLibrary() function can not load it.

Upvotes: 0

Views: 2247

Answers (1)

C.Unbay
C.Unbay

Reputation: 2826

I was able to get the best results with this argument.

objcopy --prefix-symbol=_ --input-target binary --output-target pe-x86-64 --binary-architecture i386:x86-64 some64.dll some64.o

Switching pe-i386 to pe-x86-64 and i386 to i386:x86-64 enabled me to embed my 64 bit dll into my executable without running into any binary compatibility problems. It works well on windows.

Upvotes: 1

Related Questions