alesbe / sorting-visualizer

Sorting visualizer made with SFML and C++ 📊
MIT License
16 stars 11 forks source link

[BUG]: errors while trying to generate MinGW makefile with CMake on windows #31

Open Blargian opened 1 year ago

Blargian commented 1 year ago

Describe you problem:

Windows users may need to use MinGW with CMake to compile the program. When generating a makefile for the sorting-visualizer using mingw32-make the following errors are thrown:

\sorting-visualizer\src\SortController.cpp: In member function 'void SortController::_startSort(int)':
\sorting-visualizer\src\SortController.cpp:144:71: error: no matching function for call to 'std::thread::thread(void (SortController::*)(), SortController*)'
  144 |         _animThread = std::thread(&SortController::checkSortAnim, this);
      |                                                                       ^
In file included from C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/thread:43,
                 from \sorting-visualizer\src\SortController.h:10,
                 from \sorting-visualizer\src\SortController.cpp:1:
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:156:5: note: candidate: 'std::thread::thread(std::thread&&)'
  156 |     thread(thread&& __t) noexcept
      |     ^~~~~~
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:156:5: note:   candidate expects 1 argument, 2 provided
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:120:5: note: candidate: 'std::thread::thread()'
  120 |     thread() noexcept = default;
      |     ^~~~~~
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:120:5: note:   candidate expects 0 arguments, 2 provided
\sorting-visualizer\src\SortController.cpp: In member function 'void SortController::startSort(int)':
\sorting-visualizer\src\SortController.cpp:165:81: error: no matching function for call to 'std::thread::thread(void (SortController::*)(int), SortController*, int&)'
  165 |         _sortingThread = std::thread(&SortController::_startSort, this, sortType);
      |                                                                                 ^
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:156:5: note: candidate: 'std::thread::thread(std::thread&&)'
  156 |     thread(thread&& __t) noexcept
      |     ^~~~~~
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:156:5: note:   candidate expects 1 argument, 3 provided
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:120:5: note: candidate: 'std::thread::thread()'
  120 |     thread() noexcept = default;
      |     ^~~~~~
C:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/bits/std_thread.h:120:5: note:   candidate expects 0 arguments, 3 provided
mingw32-make[2]: *** [CMakeFiles\sorting-visualizer.dir\build.make:121: CMakeFiles/sorting-visualizer.dir/src/SortController.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/sorting-visualizer.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2

Steps to reproduce (optional):

CMake -DCMAKE_C_COMPILER="C:/mingw64/bin/gcc.exe" CMake DCMAKE_CXX_COMPILER="C:/mingw64/bin/g++.exe"

Additional info (optional):

Running Windows 11 gcc.exe (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project) 12.2.0 g++.exe (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project) 12.2.0

OS

Blargian commented 1 year ago

@alesbe i'm fairly new to development in C++ so quite possible I'm just making some newbie mistake somewhere. Thought it might be good to create this issue anyway for any other users who may run into issues trying to get sorting-visualizer to work on windows. I'll keep looking into it.

alesbe commented 1 year ago

Thanks for reporting the bug!

When I was developing this, I was using Linux with CMake, I've never used CMake in Windows so I don't know what is causing the error...

Anyways, I'll look into it right now. There should be an easier way to compile the project in Windows, like the install.sh for Linux.

Here is a guide from SFML to compile it using CMake. I will try to fix it and after that, I will make an installation script for Windows. I'll keep you updated!

Blargian commented 1 year ago

Thanks for the link. I tried this morning following along with the tutorial. Was able to generate the makefile successfully but get the same errors when trying to build - it gets 66% of the way through. I suspect that maybe it has to do with mingw not having a version of GCC which supports threading or the c++11 standard by default.

I will try use a C++11 compiler for windows like MinGW-Builds rather than MinGW and see if that helps.

Blargian commented 1 year ago

@alesbe I was able to get it working on windows so I think this reported bug isn't actually a bug, just a configuration issue on my side. Once I installed MinGW-Builds and used their included version of g++ compiler rather than the one included with MinGW I was able to build without errors.

alesbe commented 1 year ago

That's so interesting! Thanks for your interest :)

I still can't compile the project on windows. Did you installed MinGW-Builds from here?

Also, a new algorithm was added to the project, you might want to pull the changes before implementing anything! :)