brummer10 / Mamba

Virtual Midi keyboard and Midi Live Looper for Jack Audio Connection Kit
BSD Zero Clause License
75 stars 5 forks source link

Compilation problem with gcc-11 #38

Closed ycollet closed 3 years ago

ycollet commented 3 years ago

Hello, I am trying to compile mamba on fedora 34 beta with gcc-11 and I met the following error message:

/usr/include/smf.h:217:1: note: 'extern "C"' linkage started here
  217 | extern "C" {
      | ^~~~~~~~~~
In file included from /usr/include/glib-2.0/glib/gatomic.h:31,
                 from /usr/include/glib-2.0/glib/gthread.h:32,
                 from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
                 from /usr/include/glib-2.0/glib.h:32,
                 from /usr/include/smf.h:221,
                 from Mamba.h:22,
                 from Mamba.cpp:22:
/usr/include/c++/11/type_traits:1250:3: error: template with C linkage
 1250 |   template<typename _Tp>
      |   ^~~~~~~~
In file included from Mamba.h:22,
                 from Mamba.cpp:22:
brummer10 commented 3 years ago

that looks pretty much like a problem in libsmf. I'll look into it, thanks for reporting. regards hermann

ycollet commented 3 years ago

I agreed. I tried to include smf.h in extern "C" in mamba.h and it doesn't fix anything. Looking into smf.h ....

brummer10 commented 3 years ago

I don't know exactly, but usually you included other headers outside the extern "C" macro, in smf.h I see that stdio.h and glib.h been included inside the macro. That may be a problem with gcc 11 but I don't know.

ycollet commented 3 years ago

I met the same kind of problem with gxtuner. gcc 11 enable c++17 by default. Maybe the problem comes from here ...

brummer10 commented 3 years ago

Ah, maybe it helps to add -std=c++11 to the CXXFLAGS in the makefile?

ycollet commented 3 years ago

No, not yet. I set CXXFLAGS=-std=C++11 and I realized that the Makefile managed CPPFLAGS instead of CXXFLAGS. So, I tried to add -std=c++11 to CPPFLAGS. But still the same problem. I am looking for a solution ...

ycollet commented 3 years ago

I tried the -fno-new-ttp-matching flags from the changeog https://gcc.gnu.org/gcc-11/changes.html But It doesn"t works.

ycollet commented 3 years ago

Finally, this combination has worked for gxtuner: export CPPFLAGS="-D__cplusplus -std=c++11 $CXXFLAGS"

ycollet commented 3 years ago

Doesn't work for Mamba. I stop for the night ...

brummer10 commented 3 years ago

The Mamba makefile use CXXFLAGS I've added the -std=gnu++14 flag now, hope that helps.

brummer10 commented 3 years ago

I do some tests with -std=gnu++17, found some issues in the Mamba source which I've solved now. But the issue with libsmf I can't reproduce here when build with gnu++17 enabled. True, I'm still on the gcc version 10.2.1

brummer10 commented 3 years ago

So I do some research on this issue, and it seems that indeed the issue is that smf.h include glib.h in a extern "C" block. That is still no problem here on debian/sid with gcc 10.2, but maybe gcc-11 is a bit more strict about that. I found a possible workaround for that, by including type_traits in a external C++ block before include smf.h Still I didn't realy know if that works or not, as we don't have gcc-11 on debian jet. You may try it your self before I push such a change to the repository. Just open the file mamba.h and insert the following block


extern "C++" {
#include <type_traits>
}

just above the line #include <smf.h>

let me know if that helps, if so I'll add it to the repository. regards hermann

ycollet commented 3 years ago

Thanks a lot, I will try ASAP.

ycollet commented 3 years ago

Works here. Thanks for this fix.

brummer10 commented 3 years ago

Okay, nice, So I've pushed it to the repository now. Closed this issue.