Pagghiu / SaneCppLibraries

Sane C++ Libraries
https://pagghiu.github.io/SaneCppLibraries
MIT License
507 stars 11 forks source link

Unable to build on Linux: different exception specifier #17

Closed codecat closed 3 months ago

codecat commented 4 months ago

I'm getting the following compilation failure. Looks like the functions in LibC.h are missing noexcept(true).

This is on gcc 13.2.1 on Fedora.

In file included from /home/nimble/dev/example/thirdparty/sc/Libraries/FileSystem/Internal/FileSystemPosix.inl:11,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/FileSystem/FileSystem.cpp:12,
                 from /home/nimble/dev/example/thirdparty/sc/SC.cpp:9:
/usr/include/string.h:43:14: error: declaration of ‘void* memcpy(void*, const void*, size_t) noexcept’ has a different exception specifier
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
In file included from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/../../File/../Strings/../Strings/../Foundation/Assert.h:6,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/../../File/../Strings/../Strings/StringIterator.h:4,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/../../File/../Strings/StringView.h:4,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/../../File/FileDescriptor.h:7,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/../Async.h:12,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/AsyncPrivate.h:2,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/AsyncLinux.inl:3,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/Async/Async.cpp:10,
                 from /home/nimble/dev/example/thirdparty/sc/SC.cpp:6:
/home/nimble/dev/example/thirdparty/sc/Libraries/Async/Internal/../../File/../Strings/../Strings/../Foundation/../Foundation/LibC.h:16:11: note: from previous declaration ‘void* memcpy(void*, const void*, SC::size_t)’
   16 |     void* memcpy(void* dst, const void* src, SC::size_t n);
      |           ^~~~~~
Pagghiu commented 4 months ago

yeah, I suspected that the LibC.h would break on some other platforms other than the ones I am actively testing (that is mainly Ubuntu regarding to Linux). I think I got a similar problem with the memchr function that has C++ mangling when including some LibC header from C++ files. As this can grow very complicated soon if you try to handle all possible linux distros, I was thinking to add a "Safety" mode where on unknown platforms I would just include the proper headers from the host toolchain...

I'm wondering if there is a way to know in the header if I am on an ubuntu system vs a Fedora system or other distros 🤔

codecat commented 4 months ago

I just ran into another problem which I assume is related then?

In file included from /home/nimble/dev/example/thirdparty/sc/Libraries/FileSystemIterator/../File/../Foundation/Span.h:4,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/FileSystemIterator/../File/FileDescriptor.h:5,
                 from /home/nimble/dev/example/thirdparty/sc/Libraries/FileSystemIterator/FileSystemIterator.h:4,
                 from /home/nimble/dev/example/main.cpp:4:
/home/nimble/dev/example/thirdparty/sc/Libraries/FileSystemIterator/../File/../Foundation/../Foundation/InitializerList.h:8:7: error: redefinition of ‘class std::initializer_list<_E>’
    8 | class initializer_list
      |       ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/range_access.h:36,
                 from /usr/include/c++/13/string:53,
                 from /home/nimble/dev/example/build/_deps/hello_imgui-src/src/hello_imgui/../hello_imgui/hello_imgui_assets.h:2,
                 from /home/nimble/dev/example/build/_deps/hello_imgui-src/src/hello_imgui/../hello_imgui/hello_imgui.h:9,
                 from /home/nimble/dev/example/main.cpp:1:
/usr/include/c++/13/initializer_list:45:11: note: previous definition of ‘class std::initializer_list<_E>’
   45 |     class initializer_list
      |           ^~~~~~~~~~~~~~~~
Pagghiu commented 4 months ago

yes that's the same problem, the "safety mode" should also include too.

I will be working on fixing this btw.

Pagghiu commented 4 months ago

Ok I see the issue. If you compile the SC.cpp unity build file with -fno-rtti -fno-exceptions it should work fine.

I think I need to add this to the "how to use / integrate in your project" instructions.

If I can detect whether these flags are on or off I could also probably tackle the required changes automatically

Pagghiu commented 3 months ago

Hi @codecat , I have been also doing some additional fixes.

Now if you pull the latest main branch and compile with exceptions enabled, LibC.h will include instead of trying to use its own forward declarations. As you are using The standard C++ library, you should also define SC_COMPILER_ENABLE_STD_CPP=1 and that should take care of the <initializer_list> issue.

Please let me know if this is fixing your issues.

codecat commented 3 months ago

Looks to be working! Thanks for the fixes! :tada: