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

Trouble compiling with gcc 11.1 #79

Open
MNRK01 opened this issue Jul 18, 2021 · 4 comments
Open

Trouble compiling with gcc 11.1 #79

MNRK01 opened this issue Jul 18, 2021 · 4 comments

Comments

@MNRK01
Copy link

MNRK01 commented Jul 18, 2021

Hi,

I have been trying to compile this code from boost 1.76.0 with mingw-w64 gcc 11:

/*  Copyright 2020 Rene Rivera
 *  Distributed under the Boost Software License, Version 1.0.
 *  (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 */

/*
This program is a compile test for support of C++11. If it compiles
successfully some key parts of C++11 the B2 engine requires are
available. This is used by the build script to guess and check the
compiler to build the engine with.
*/

// Some headers we depend on..
#include <thread>


int main()
{
    // Check for basic thread calls.
    { auto _ = std::thread::hardware_concurrency(); }
}

I get the following error with gcc 11.1, but not with gcc 10.3 or other earlier gcc 10:

In file included from C:/mingw-gcc-11.1.0/i686-1110-win32-sjlj-rt_v9-rev0/mingw32/opt/include/mingw-std-threads/thread:3,
                 from check_cxx11.cpp:14:
C:/mingw-gcc-11.1.0/i686-1110-win32-sjlj-rt_v9-rev0/mingw32/opt/include/mingw-std-threads/mingw.thread.h:330:24: error: 'class mingw_stdthread::thread' conflicts with a previous declaration
  330 | using mingw_stdthread::thread;
      |                        ^~~~~~
In file included from C:/mingw-gcc-11.1.0/i686-1110-win32-sjlj-rt_v9-rev0/mingw32/lib/gcc/i686-w64-mingw32/11.1.0/include/c++/thread:43,
                 from C:/mingw-gcc-11.1.0/i686-1110-win32-sjlj-rt_v9-rev0/mingw32/opt/include/mingw-std-threads/thread:2,
                 from check_cxx11.cpp:14:
C:/mingw-gcc-11.1.0/i686-1110-win32-sjlj-rt_v9-rev0/mingw32/lib/gcc/i686-w64-mingw32/11.1.0/include/c++/bits/std_thread.h:62:9: note: previous declaration 'class std::thread'
   62 |   class thread
      |         ^~~~~~

It seems this error is new to gcc 11. Commenting out using mingw_stdthread::thread on line 330 of mingw.thread.h allows me to get past this error, but causes downstream errors when building boost as one can expect.

I'll say that I m surprised that it appears no one else has seen this issue with mingw-w64 gcc 11. I'm wondering if this is on my end. I build my own gcc with scripts from mingw-builds.

Thank you for making mingw-std-threads available and also for any help that you can provide on this issue.

@Jamaika1
Copy link

Jamaika1 commented Jul 20, 2021

It looks like this to me. This is not a bug, but a deliberate action by the gcc developers not to use mingwstd under the pretext of using newer languages than C++11/14.
Nobody's interested in improving mingwstd because there are no funds for it. In newer languages there are new functions that are not compatible with linux with windows.
Did I manage to compile something with boost? Yes
I compiled boost 1.77.0 beta with libwebp2. Is it working properly? Who knows that.
https://github.com/Jamaika1/mingw_std_threads/
I do not take any responsibility for the given link.

@MNRK01
Copy link
Author

MNRK01 commented Aug 7, 2021

Hi,

Thanks for making https://github.com/Jamaika1/mingw_std_threads/ available. The thread part now works well with gcc 11.1 based on limited testing of the code in my original report.

However, I quickly ran into an issue trying to compile libicu which boost/regex needs optionally. The error is distilled down to the definition of class mutex being protected by #ifdef _GLIBCXX_HAS_THREADS in std_mutex.h. Since I am compiling gcc with win32 thread model, gthreads is not available to me and running:

printf '#include <mutex>\nstd::mutex test_mutex;int main(){return 0;}' | g++ -x c++ -E -dM - | grep -i THREAD

confirms that I don't have _GLIBCXX_HAS_THREADS defined.

I think that @Jamaika1's approach to the headers makes sense to me to avoid the namespace clash issues referenced above. It does appear that there is work needed to improve the code so that all the mingw-std-threads headers work well.

I should have pointed out in my initial report that I run the Powershell script Generate-StdLikeHeaders.ps1 under utility_scripts to use mingw-std-threads, i.e. I don't use CMake. Not sure if that is relevant to my error report.

I appreciate your work very much.

@Jamaika1
Copy link

Jamaika1 commented Aug 8, 2021

My mistake is that I defined it together. When we use MINGWSTD we don't use _GLIBCXX_HAS_GTHREADS. I split definitions.
The most modified in GCC is definition <type_traits>. The modifications I have posted may be difficult to apply after a month.
https://github.com/gcc-mirror/gcc/commits/master/libstdc%2B%2B-v3/include/std/type_traits
It seems that the function mingw invoke doesn't apply when compiling C++11 in cpp if files don't contain thread. Interestingly this is just an internal function to mingw thread or it's a bug.

@MNRK01
Copy link
Author

MNRK01 commented Aug 15, 2021

It works much better now. I can build libicu and boost. I'm continuing to test other C++11 code. It looks like you no longer need to modify type_traits which is great news.

Is there any hope of backporting your code structure into this mingw-std-threads repo?
Also, your code is setup for upstreaming into mingw-w64. Is that a possibility?

Thanks for working on it!

manxorist added a commit to OpenMPT/openmpt that referenced this issue May 4, 2022
…mingw.mutex.h instead of mingw.thread.h because GCC11 broke mingw-std-threads' thread implementation. See <meganz/mingw-std-threads#79> and <https://forum.openmpt.org/index.php?topic=6822>.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@17309 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this issue May 4, 2022
Merged revision(s) 17309 from trunk/OpenMPT:
[Fix] build: Autotools: Change detection of mingw-std-threads to use mingw.mutex.h instead of mingw.thread.h because GCC11 broke mingw-std-threads' thread implementation. See <meganz/mingw-std-threads#79> and <https://forum.openmpt.org/index.php?topic=6822>.
........
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.29@17311 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this issue May 4, 2022
Merged revision(s) 17309 from trunk/OpenMPT:
[Fix] build: Autotools: Change detection of mingw-std-threads to use mingw.mutex.h instead of mingw.thread.h because GCC11 broke mingw-std-threads' thread implementation. See <meganz/mingw-std-threads#79> and <https://forum.openmpt.org/index.php?topic=6822>.
........
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.28@17312 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this issue May 4, 2022
[Fix] build: Autotools: Change detection of mingw-std-threads to use mingw.mutex.h instead of mingw.thread.h because GCC11 broke mingw-std-threads' thread implementation. See <meganz/mingw-std-threads#79> and <https://forum.openmpt.org/index.php?topic=6822>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.30@17310 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this issue May 25, 2022
[Mod] libopenmpt: Deprecate the use of mingw-std-threads. See <https://forum.openmpt.org/index.php?topic=6822>, <meganz/mingw-std-threads#79> and <gcc-mirror/gcc@b204d77>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.30@17365 56274372-70c3-4bfc-bfc3-4c3a0b034d27
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 15, 2022
### libopenmpt 0.6.4 (2022-06-12)

 *  [**Bug**] openmpt123: Linking failed when using Autotools build system
    targeting MinGW.
 *  [**Bug**] tests: Linking failed when using Autotools build system targeting
    MinGW.
 *  [**Bug**] examples: Linking failed when using Autotools build system
    targeting MinGW.

 *  [**Change**] Support for mingw-std-threads when building for MinGW targets
    is now deprecated because this is not supported for GCC 11 or later (see
    <meganz/mingw-std-threads#79>).

 *  Ping-pong sample loops sometimes stopped playing at the end of the loop.
socram8888 added a commit to socram8888/windows-fido-bridge that referenced this issue Feb 15, 2023
The support for MinGW >= 11 is broken (meganz/mingw-std-threads#79),
which prevents building on Debian Bookworm.

This commit fixes it by explicitely building with the POSIX variant of MinGW, which has built-in
support for std threads.
socram8888 added a commit to socram8888/windows-fido-bridge that referenced this issue Feb 15, 2023
The support for MinGW >= 11 is broken (meganz/mingw-std-threads#79),
which prevents building on Debian Bookworm.

This commit fixes it by explicitely building with the POSIX variant of MinGW, which has built-in
support for std threads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants