johnmcfarlane / cnl

A Compositional Numeric Library for C++
Boost Software License 1.0
632 stars 63 forks source link

Build error on v1.1.2: redefinition of ‘struct std::hash<std::filesystem::__cxx11::path>’ #1047

Open eduvfalc opened 5 months ago

eduvfalc commented 5 months ago

Hi,

When trying to build and install CNL v1.1.2 I ran through the following error:

[ 95%] Building CXX object test/unit/CMakeFiles/test-unit-presentations-cppcon2017.dir/presentations/cppcon2017.cpp.o
/home/falco/repos/cnl-1.1.2/test/unit/presentations/cppcon2017.cpp:24:13: error: redefinition of ‘struct std::hash<std::filesystem::__cxx11::path>’
   24 | struct std::hash<filesystem::path> {
      |             ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/filesystem:45,
                 from /home/falco/repos/cnl-1.1.2/test/unit/presentations/cppcon2017.cpp:16:
/usr/include/c++/11/bits/fs_path.h:1361:10: note: previous definition of ‘struct std::hash<std::filesystem::__cxx11::path>’
 1361 |   struct hash<filesystem::path>
      |          ^~~~~~~~~~~~~~~~~~~~~~

It happens in both cppcon2017.cpp and cppcon2018.cpp. Any hint on what might be going wrong here or what I can be missing?

Note: I am running it on WSL Ubuntu 22.04

johnmcfarlane commented 5 months ago

Hi Eduardo,

Thanks for letting me know. If you could provide any of the info listed here, it would be helpful. In particular, compiler version and flags are likely to explain this.

That specialization was previously not defined until C++17. Likely, a toolchain defined this in its standard library implementation since a certain version. It would be useful to confirm this. It would appear benign though if it's the only error you're seeing.

Cheers, John

eduvfalc commented 5 months ago

Hi John,

Thanks for the prompt reply. For your convenience, please find below the template-friendly problem I am facing and further info.

Describe the bug

When trying to build and install CNL v1.1.2 I ran through the following error:

[ 95%] Building CXX object test/unit/CMakeFiles/test-unit-presentations-cppcon2017.dir/presentations/cppcon2017.cpp.o
/home/falco/repos/cnl-1.1.2/test/unit/presentations/cppcon2017.cpp:24:13: error: redefinition of ‘struct std::hash<std::filesystem::__cxx11::path>’
   24 | struct std::hash<filesystem::path> {
      |             ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/filesystem:45,
                 from /home/falco/repos/cnl-1.1.2/test/unit/presentations/cppcon2017.cpp:16:
/usr/include/c++/11/bits/fs_path.h:1361:10: note: previous definition of ‘struct std::hash<std::filesystem::__cxx11::path>’
 1361 |   struct hash<filesystem::path>
      |          ^~~~~~~~~~~~~~~~~~~~~~

It happens in both cppcon2017.cpp and cppcon2018.cpp.

To Reproduce

Run the following commands:

mkdir build && cd build
cmake ..
cmake --build . --target install

Expected behavior

Files successfully installed in the system.

Desktop

OS: Ubuntu 22.04.3 LTS Jammy CMake: 3.22.1 Compilers: gcc/g++ 11.4.0 Compiler flags used: default values apart from those set by the CNL build structure Conan: 2.0.17 CNL: Latest release, v1.1.2

Please let me know if you need more information.

eduvfalc commented 5 months ago

Hi John,

I downgraded my gcc/g++ compilers to version 10.5 instead of 11.4. Now the build is successful. The issue is not present in my system anymore, so I guess we can close this one.

johnmcfarlane commented 5 months ago

Please don't close. CNL is intended to work with both versions of the compiler.

eduvfalc commented 5 months ago

Ok, let me know what else you will need from me and I can feed you with more details of the issue. I am still able to reproduce it should I upgrade the version.