Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ binaries incompatible with MinGW #5052

Open
ikocs opened this issue Apr 12, 2024 · 7 comments
Open

C++ binaries incompatible with MinGW #5052

ikocs opened this issue Apr 12, 2024 · 7 comments
Labels
a:language-c++ C++ API, codegen, CMake build system (mS,mO) packaging Packaging and ease of downloading/obtaining Slint

Comments

@ikocs
Copy link

ikocs commented Apr 12, 2024

Hello!

I wanted to get acquainted with Slint with the slint-cpp-template example. I tried to build a project using MinGW. I installed it using msys. However, I received an error when building:

====================[ Build | my_application | Debug-MinGW GCC ]================
C:\Users\Elf\AppData\Local\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe --build F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc --target my_application -j 10
[1/3] Generating appwindow.h
[2/3] Building CXX object CMakeFiles/my_application.dir/src/main.cpp.obj
FAILED: CMakeFiles/my_application.dir/src/main.cpp.obj 
C:\msys64\mingw64\bin\g++.exe  -IF:/tests/slint-cpp-template/cmake-build-debug-mingw-gcc -isystem "C:/Program Files/Slint-cpp 1.5.1/include/slint" -g -std=gnu++20 -fdiagnostics-color=always /bigobj -MD -MT CMakeFiles/my_application.dir/src/main.cpp.obj -MF CMakeFiles\my_application.dir\src\main.cpp.obj.d -o CMakeFiles/my_application.dir/src/main.cpp.obj -c F:/tests/slint-cpp-template/src/main.cpp
g++.exe: warning: /bigobj: linker input file unused because linking not done
g++.exe: error: /bigobj: linker input file not found: No such file or directory
ninja: build stopped: subcommand failed.

After that I changed the compiler to MSVC. In this case, the build went without problems and the test application launched. I would like to understand why the example did not work with GCC.

This is probably important too. The CMAke console also displays a warning related to /bigobj:

C:\Users\Elf\AppData\Local\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/Elf/AppData/Local/Programs/CLion/bin/ninja/win/x64/ninja.exe -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe -G Ninja -S F:\tests\slint-cpp-template -B F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: F:/tests/slint-cpp-template/cmake-build-debug-mingw-gcc

Problems were encountered while collecting compiler information:
	cc1plus.exe: fatal error: /bigobj: No such file or directory

[Finished]
@tronical
Copy link
Member

We add /bigobj to the link line only if CMake believes that it's building with MSVC. How did you invoke cmake when this failed?

@ikocs
Copy link
Author

ikocs commented Apr 12, 2024

We add /bigobj to the link line only if CMake believes that it's building with MSVC. How did you invoke cmake when this failed?

I use clion for build project. But as I understand it, the following command was executed:

====================[ Build | my_application | Debug-MinGW GCC ]================
C:\Users\Elf\AppData\Local\Programs\CLion\bin\cmake\win\x64\bin\cmake.exe --build F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc --target my_application -j 10

I tried using the system CMAKE. The result is the same. Path to cmake IDE changes:

====================[ Build | my_application | Debug-MinGW GCC ]================
"C:\Program Files\CMake\bin\cmake.exe" --build F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc --target my_application -j 10
[1/3] Generating appwindow.h
[2/3] Building CXX object CMakeFiles/my_application.dir/src/main.cpp.obj
FAILED: CMakeFiles/my_application.dir/src/main.cpp.obj 
C:\msys64\mingw64\bin\g++.exe  -IF:/tests/slint-cpp-template/cmake-build-debug-mingw-gcc -isystem "C:/Program Files/Slint-cpp 1.5.1/include/slint" -g -std=gnu++20 -fdiagnostics-color=always /bigobj -MD -MT CMakeFiles/my_application.dir/src/main.cpp.obj -MF CMakeFiles\my_application.dir\src\main.cpp.obj.d -o CMakeFiles/my_application.dir/src/main.cpp.obj -c F:/tests/slint-cpp-template/src/main.cpp
g++.exe: warning: /bigobj: linker input file unused because linking not done
g++.exe: error: /bigobj: linker input file not found: No such file or directory
ninja: build stopped: subcommand failed.

@tronical
Copy link
Member

Hm, could it be that your build directory was initially configured for MSVC?

If you remove F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc entirely once and then re-build (re-configure), does the problem still exist?

@ikocs
Copy link
Author

ikocs commented Apr 12, 2024

Two more possibly important points:

  1. I installed Slint from .exe for Win11.
  2. My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.21)
project(my_application LANGUAGES CXX)

set(CMAKE_PREFIX_PATH "C:/Program Files/Slint-cpp 1.5.1")

find_package(Slint QUIET)

if (NOT Slint_FOUND)
  message("Slint could not be located in the CMake module search path. Downloading it from Git and building it locally")
  include(FetchContent)
  FetchContent_Declare(
    Slint
    GIT_REPOSITORY https://github.com/slint-ui/slint.git
    # `release/1` will auto-upgrade to the latest Slint >= 1.0.0 and < 2.0.0
    # `release/1.0` will auto-upgrade to the latest Slint >= 1.0.0 and < 1.1.0
    GIT_TAG release/1
    SOURCE_SUBDIR api/cpp
  )
  FetchContent_MakeAvailable(Slint)
endif (NOT Slint_FOUND)

add_executable(my_application src/main.cpp)
target_link_libraries(my_application PRIVATE Slint::Slint)
slint_target_sources(my_application ui/appwindow.slint)
# On Windows, copy the Slint DLL next to the application binary so that it's found.
if (WIN32)
    add_custom_command(TARGET my_application POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:my_application> $<TARGET_FILE_DIR:my_application> COMMAND_EXPAND_LISTS)
endif()
  1. First start CMake:

Hm, could it be that your build directory was initially configured for MSVC?

If you remove F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc entirely once and then re-build (re-configure), does the problem still exist?

"C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/Elf/AppData/Local/Programs/CLion/bin/ninja/win/x64/ninja.exe -DCMAKE_C_COMPILER=C:/msys64/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe -G Ninja -S F:\tests\slint-cpp-template -B F:\tests\slint-cpp-template\cmake-build-debug-mingw-gcc
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.5s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_C_COMPILER


-- Build files have been written to: F:/tests/slint-cpp-template/cmake-build-debug-mingw-gcc

Problems were encountered while collecting compiler information:
	cc1plus.exe: fatal error: /bigobj: No such file or directory

[Finished]

The compiler is detected correctly. Then the problem repeated during the assembly stage.

@ikocs
Copy link
Author

ikocs commented Apr 12, 2024

I found the following piece of code in the file "C:\Program Files\Slint-cpp 1.5.1\lib\cmake\Slint\SlintTargets.cmake":

# Create imported target Slint::Slint
add_library(Slint::Slint INTERFACE IMPORTED)

set_target_properties(Slint::Slint PROPERTIES
  INTERFACE_COMPILE_FEATURES "cxx_std_20"
  INTERFACE_COMPILE_OPTIONS "/bigobj"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/slint"
  INTERFACE_LINK_LIBRARIES "Slint::slint-cpp"
)

Could this be causing the problem? I don't know cmake very well, unfortunately(

@ogoffart
Copy link
Member

The problem is that our binaries are built for the msvc target, and they are incompatible with mingw.

This /bigobj flag is probably only the tip of the iceberg of incompatibilities.

@tronical: Should we perhaps build both msvc and mingw binaries and have two packages? Or would it be possible to merge the two in a single package?

@ogoffart ogoffart transferred this issue from slint-ui/slint-cpp-template Apr 12, 2024
@ogoffart ogoffart changed the title Link error with MinGW C++ binaries incompatible with MinGW Apr 12, 2024
@ogoffart ogoffart added the a:language-c++ C++ API, codegen, CMake build system (mS,mO) label Apr 12, 2024
@tronical
Copy link
Member

Right. I suspect that a unified binary package might be possible - but it would require stitching two independent builds together. I think for now the best course of action is to rename our binary package to have a -MSVC suffix and add a -MinGW package separately.

@ogoffart ogoffart added the packaging Packaging and ease of downloading/obtaining Slint label Apr 12, 2024
tronical added a commit that referenced this issue Apr 12, 2024
Add a -MSVC suffix to our binary package (and prepare for future MinGW build)

cc #5052
tronical added a commit that referenced this issue Apr 15, 2024
Add a -MSVC suffix to our binary package (and prepare for future MinGW build)

cc #5052
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-c++ C++ API, codegen, CMake build system (mS,mO) packaging Packaging and ease of downloading/obtaining Slint
Projects
None yet
Development

No branches or pull requests

3 participants