0
votes

I know this is a very often asked question and I really browsed through all of the answers already but I could not find my problem and the solution for it as well.

Preface

Using the Cygwin Toolchain within CLion to build a 64bit C++ program worked like a charm. No errors or whatsoever. I then tried to do the same for 32bit and quickly realised it is a lot harder to understand.

CMakeList

Here I added the -m32 flag to the already working CMakeLists.txt

# cmake_minimum_required(VERSION <specify CMake version here>)
project(my_program)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS -m32)

add_library(my_program SHARED library.cpp)

I then used CygWin to download plenty of c++ compilers just to get sure I have at least one of them that might work.

Here is the way I configure it for the 32bit build

enter image description here

After doing so CMake is rebuilding the build files and then I started compiling the project.

Following Error messages appear (truncated because they actually all are the same but with different "missing" libraries that couldn't be found)

C:\Users\xetra11\.CLion2018.2\system\cygwin_cmake\bin\cmake.exe --build /cygdrive/c/Development/Github/CoopR-HQ-Extension/cmake-build-default --target all -- -j 10
[ 50%] Linking CXX shared library cygCoopR_HQ_Extension.dll
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc

C++ compilers used These are the compilers I tried to use. They all yield slighty different error messages but all are unified in the rant for not finding a library

Cygwin compilers:

  • C:\cygwin64\bin\x86_64-pc-cygwin-gcc.exe (the one used in this question)
  • C:\cygwin64\bin\x86_64-pc-cygwin-gcc-7.3.0.exe
  • C:\cygwin64\bin\x86_64-pc-cygwin-g++.exe
  • C:\cygwin64\bin\x86_64-pc-cygwin-c++.exe
  • C:\cygwin64\bin\i686-pc-cygwin-c++.exe (broken CMake threw errors: link)
  • C:\cygwin64\bin\i686-pc-cygwin-cpp.exe (broken CMake threw errors: link)
  • C:\cygwin64\bin\i686-pc-cygwin-g++.exe (error occured: link)
  • C:\cygwin64\bin\i686-pc-cygwin-gcc-6.4.0.exe (broken CMake threw errors: link)
  • C:\cygwin64\bin\i686-pc-cygwin-gcc.exe (broken CMake threw errors: link)

MinGW compilers:

  • C:\cygwin64\bin\x86_64-w64-mingw32-c++.exe
  • C:\cygwin64\bin\x86_64-w64-mingw32-cpp.exe (broken CMake threw errors: link)
  • C:\cygwin64\bin\x86_64-w64-mingw32-g++.exe
  • C:\cygwin64\bin\x86_64-w64-mingw32-gcc-6.4.0.exe
  • C:\cygwin64\bin\x86_64-w64-mingw32-gcc.exe
  • C:\cygwin64\bin\i686-w64-mingw32-c++.exe (no errors)

The last one did not threw any errors but when checking the .DLL with Dependency Walker I found out that all linked .DLLs to this still rely on x64 and therefore Error: Modules with different CPU types were found.

enter image description here

I am a bit tired now and really would appreciate some hints how to get this stuff build the right way. I already think I understood the fact that I have to bring in 32bit libraries. But I don't really know how and why. I assumed that the toolchain have this out of the box.

Please mind that I am fairly unused to C++ on windows.

1

1 Answers

0
votes

It seems as first that you need to define if you want to build a windows program or a cygwin one. They are not the same as any cygwin program depends on the cygwin1.dll of his own architecture.

On a 64bit system x86_64-pc-cygwin-gcc.exe is the same than gcc.exe and the same of x86_64-pc-cygwin-gcc-7.3.0.exe.
https://cygwin.com/packages/x86_64/gcc-core/gcc-core-7.3.0-3
They all produce a 64 bit cygwin program.

The simple way to produce a 32bit cygwin program is to install the 32bit version of cygwin and to work on that. Cygwin 32bit and 64bit can be installed in parallel and do not interfere each other.

The alternative solution, not recommended, is to use the cross compiler from 64 to 32 bit: cygwin32-gcc-core and the associate binutils
https://cygwin.com/packages/x86_64/cygwin32-gcc-core/cygwin32-gcc-core-7.3.0-1 https://cygwin.com/packages/x86_64/cygwin32-binutils/cygwin32-binutils-2.29-1

If you are trying to build a Windows program you need to use a cross compiler from Cygwin 64 bit to Windows. For 64 bit target you need :mingw64-x86_64-gcc-core and mingw64-x86_64-binutils https://cygwin.com/packages/x86_64/mingw64-x86_64-gcc-core/mingw64-x86_64-gcc-core-7.3.0-1 https://cygwin.com/packages/x86_64/mingw64-x86_64-binutils/mingw64-x86_64-binutils-2.31.1.be46fa23-1

For 32bit target you need: mingw64-i686-gcc-core and mingw64-i686-binutils https://cygwin.com/packages/x86_64/mingw64-i686-gcc-core/mingw64-i686-gcc-core-7.3.0-1 https://cygwin.com/packages/x86_64/mingw64-i686-binutils/mingw64-i686-binutils-2.31.1.be46fa23-1

No compiler on cygwin is built with double architecture capability.