Reputation: 33
I need to build a shared library on windows (dll) in 32bit and 64bit.
The build is controlled with cmake, the compiler is mingw64
This is my cmake file:
#64Bit Build (works fine)
ADD_LIBRARY(mylib SHARED mylib.c)
SET_TARGET_PROPERTIES(mylib PROPERTIES PREFIX "")
target_link_options(mylib PUBLIC -Wl,--exclude-all-symbols -s -Wl,--gc-sections -Wl,-Map=output.map )
#32Bit Build (linking issues)
ADD_LIBRARY(mylib32 SHARED mylib.c)
SET_TARGET_PROPERTIES(mylib32 PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
target_link_options(mylib32 PUBLIC --verbose -Wl,--exclude-all-symbols -s -Wl,--gc-sections -Wl,-Map=output.map)
I get a lot of complaints during linking due to 32Bit incomatibility of many linked libraries. I can reduce the amount of complaints, when I am specifically add 32Bit libraries to the search path like this:
target_link_options(mylib32 PUBLIC --verbose -Wl,--exclude-all-symbols -s -Wl,--gc-sections -Wl,-Map=output.map -L/msys64/mingw32/lib -L/msys64/mingw32/i686-w64-mingw32/lib -L/msys64/mingw32/lib/gcc/i686-w64-mingw32/10.3.0)
But there are still some incompatibilities left: like the dllcrt.a which is always linked from the 64Bit mingw path, which seems kind of hard coded into gcc/ld.
I even tried to use an empty spec fiel, which gave nor results:
target_link_options(mylib32 PUBLIC -specs=myspe --verbose -Wl,--exclude-all-symbols -s -Wl,--gc-sections -Wl,-Map=output.map -L/msys64/mingw32/lib -L/msys64/mingw32/i686-w64-mingw32/lib -L/msys64/mingw32/lib/gcc/i686-w64-mingw32/10.3.0)
Typical error message I get:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/lib/dllcrt2.o' is incompatible with i386 output
Upvotes: 0
Views: 1669
Reputation: 33
I just figured out a solution for my case:
the crt* stuff is startup code, which is not needed in the case of libraries.
So I added the -nostartfiles
flag, and my library links fine.
I guess in case off an application one can probably link the 32bit startfiles manualy as a workaround.
SET_TARGET_PROPERTIES(amprio_seednkey32 PROPERTIES PREFIX "" COMPILE_FLAGS "-m32 -nostartfiles" LINK_FLAGS "-m32 -nostartfiles")
Anyhow, this all feels like a dirty Workaround, I still wonder what is the best way to link 32Bit and 64Bit using mingw-w64.
Upvotes: 0