jmeubank / tdm-gcc

TDM-GCC is a cleverly disguised GCC compiler for Windows!
https://jmeubank.github.io/tdm-gcc/
584 stars 49 forks source link

cmake -m32 or -m64 #16

Closed sonoro1234 closed 4 years ago

sonoro1234 commented 4 years ago

Hi,

Trying to compile with TDM-GCC-32 gave me error about not being able to find dsound.h so I tried with TDM-GCC-64: (which has dsound.h)

I found this mail thread regarding CMake settings for TDM -m32 or -m64 flags: https://cmake.org/pipermail/cmake/2017-December/066798.html

I used it in command line cmake invocation as:

cmake -DCMAKE_C_FLAGS_INIT=-m32 -DCMAKE_CXX_FLAGS_INIT=-m32 -DCMAKE_EXE_LINKER_FLAGS_INIT=-m32 -DCMAKE_MODULE_LINKER_FLAGS_INIT=-m32 -DCMAKE_SHARED_LINKER_FLAGS_INIT=-m32 ..

I think it would be useful adding it to readme

Althought perhaps something is missing: Compiling SuperCollider for 32 bits stopped after

[ 80%] Linking CXX executable Release\sclang.exe
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `CMakeFiles\sclang.dir/objects.a(sclang.rc.obj)' is incompatible with i386 output
collect2.exe: error: ld returned 1 exit status
lang\CMakeFiles\sclang.dir\build.make:106: recipe for target 'lang/Release/sclang.exe' failed
jmeubank commented 4 years ago

Generally there are many build systems that can drive GCC (and TDM-GCC), so maybe it needs to go in the CMake README? But here's another way to solve it: https://github.com/jmeubank/tdm-gcc-installer/blob/master/CMakeLists.txt#L10-L12:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=gnu++11 -m32")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -F pe-i386")
sonoro1234 commented 4 years ago

But this requires to modify CMakeLists.txt which is not possible in my usecase!!

jmeubank commented 4 years ago

Hi @sonoro1234 , I closed this issue because TDM-GCC appears to be operating as designed and in line with expectations set by the GCC and MinGW-w64 projects around the use of flags to govern 32-bit and 64-bit output. You also hit a 32/64-bit incompatibility that needs to be fixed by invoking the resource compiler, windres, with the right flags. CMake probably provides appropriate invocations for your use case.

Since TDM-GCC is currently a one-man show, please commit to doing research and experimentation to solve issues like this. :)

sonoro1234 commented 4 years ago

(Just for future reference and without intention to bother you at all)

I setted the above flags in a toolchain file (dropping -fno-rtti because boost complain about it ) as:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -m32")
set(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")

but the problem still persists The cause seems to be that CMAKE_RC_COMPILE_OBJECT is set in CMakeLists.txt as;

SET(CMAKE_RC_COMPILE_OBJECT
 "<CMAKE_RC_COMPILER> -O coff <DEFINES>  -i <SOURCE> -o <OBJECT>")

skipping <FLAGS>. But, what is worse, if I add <FLAGS> there are other flags from add_definitions that get mixed with RC_FLAGS so that windres complains and refuses to compile. It seems a cmake bug!!! https://gitlab.kitware.com/cmake/cmake/-/issues/12998

Solved changing CMAKE_RC_COMPILE_OBJECT in repository to be compiled to:

SET(CMAKE_RC_COMPILE_OBJECT
 "<CMAKE_RC_COMPILER> ${CMAKE_RC_FLAGS} -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")