0

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.

xetra11
  • 7,671
  • 14
  • 84
  • 159

1 Answers1

0

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.

matzeri
  • 8,062
  • 2
  • 15
  • 16
  • Wait do you mean the `setup-x86.exe` from https://cygwin.com/install.html ? Because I thought it is just the executable for the installer GUI for a 32bit Windows version? Or does it have the toolchain to compile 32bit programs?? – xetra11 Nov 14 '18 at 20:17
  • 1
    `setup-x86.exe` install Cygwin 32 bit , `setup-x86_64.exe` install cygwin 64 bit. The two sytems offer almost all the same packages – matzeri Nov 14 '18 at 20:19
  • Alright see the problem for me is that I see dozent of packages and I just can't figure out what I need. You mentioned that the *simple* way is to install the 32bit of cygwin. Can you tell me what that exactly is? Do you mean a specific compiler or a .dll and what is it full qualifing name to look for in the package manager? – xetra11 Nov 14 '18 at 20:24
  • 1
    Why you need to build a 32bit program on your 64bit Cygwin ? – matzeri Nov 14 '18 at 20:28
  • I don't really know what you mean with "on your 64bit Cygwin". I *simply* need to compile a program as 32bit for windows. And suggested to use 32bit Cygwin. Maybe I don't really understand what Cygwin is? You sound like Cygwin is an own operation system I want to compile for? Do I misunderstand something here very much? – xetra11 Nov 14 '18 at 20:32
  • 1
    Cygwin is a Posix enviroment, it acts as pseudo-OS on top of Windows. Cygwin program are different from windows one and require the `cygwin1.dll` as foundation of their behaviour. There are two flavours, one for 32bit and one for 64bit. Windows at 64bit can run both. Windows at 32bit only Cygwin at 32bit – matzeri Nov 14 '18 at 20:37
  • Wow ok then I am on a dead end here it seems. So to compile purely for windows and not for any special-OS environment there is not alternative besides Visual C++ compiler? – xetra11 Nov 14 '18 at 20:43
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183659/discussion-between-matzeri-and-xetra11). – matzeri Nov 14 '18 at 20:46