I am on Windows, and I am using the version of g++
that comes with mingw-64
. I have a file on my computer called lua51.dll
. When I try to run the following command :
g++ -shared -fPIC -o stuff.dll -llua51 stuff.cpp
I get the following error:
C:/Program Files/LOVE/lua51.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make: *** [main] Error 1
How can I fix this? Please let me know if more information is needed; I am a complete beginner to compilation.
This is an issue you get when you try to include a 64-bit library when running a 32-bit version of g++
or even gcc
.
I thought that that the version of g++.exe
that comes with mingw-64
would produce 64-bit code, but it turns out this isn't true; it still only produces 32-bit code. In my case, lua51.dll
is 64-bit, which is an issue since I was using the version of g++
that produces 32-bit code.
Instead, you need to use x86_64-w64-mingw32-g++.exe
, which can be found in the same folder as g++.exe
. This is the version of g++
that will produce 64-bit code.