scylladb / seastar

High performance server-side application framework
http://seastar.io
Apache License 2.0
8.15k stars 1.53k forks source link

cmake: correctly detect compiler for std::filesystem - gcc-9 cannot have -lstdc++-fs #648

Open emaxerrno opened 5 years ago

emaxerrno commented 5 years ago

Adding a small modification to the std::filesystem test (cmake/code_test/StdFilesystem_test.cc) to trigger it

#include <iostream>
#if __cplusplus >= 201703L && __has_include(<filesystem>)
#include <filesystem>
namespace filesystem = std::filesystem;
#else
#include <experimental/filesystem>
namespace filesystem = std::experimental::filesystem;
#endif

int main() {
    try{
        filesystem::path path("/root");
        (void)path;
    } catch(const filesystem::filesystem_error& e){
        std::cerr << "filesystem_error workaround: " << e.what() << std::endl;
    }
}
➜  code_tests git:(feature/fs_exception) ✗ g++ --version
g++ (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

➜  code_tests git:(feature/fs_exception) ✗ g++ -std=c++17  StdFilesystem_test.cc  
➜  code_tests git:(feature/fs_exception) ✗ echo $?                              
0
➜  code_tests git:(feature/fs_exception) ✗ g++ -std=c++14  StdFilesystem_test.cc
/bin/ld: /tmp/ccvDEC0g.o:(.gcc_except_table+0x20): undefined reference to `typeinfo for std::experimental::filesystem::v1::__cxx11::filesystem_error'
/bin/ld: /tmp/ccvDEC0g.o: in function `std::experimental::filesystem::v1::__cxx11::path::path<char [6], std::experimental::filesystem::v1::__cxx11::path>(char const (&) [6])':
StdFilesystem_test.cc:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2IA6_cS3_EERKT_[_ZNSt12experimental10filesystem2v17__cxx114pathC5IA6_cS3_EERKT_]+0x5b): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
➜  code_tests git:(feature/fs_exception) ✗ 

The issue is:

  1. gcc-9 does not have -lstdc++-fs
  2. if user passes -DSeastar_CXX_DIALECT=c++14 to cmake w/ a machine that only has gcc-9 it will incorrectly configure the test as it is incompatible because -libstdc++-fs does not exist / not install when one does dnf / apt-get install gcc-9

Note: I haven't tested using a machine w/ both gcc-8 and gcc-9

sassyn commented 5 years ago

I can report this step is working with GCC-8 on ubunu 18.04

kostja commented 5 years ago

Your test doesn't compile because of a missing header, #include < iostream >. I perhaps could submit it to the mailing list for you.

emaxerrno commented 5 years ago

@sassyn - yes, i said gcc-9 , gcc-8 has -lstdc++-fs @kostja - the sample above has iostream include. It's not iostream that's the problem is the std::filesystem::filesystem_error

sassyn commented 5 years ago

Thank you!

On Tue, 4 Jun 2019 at 23:59 Alexander Gallego notifications@github.com wrote:

@sassyn https://github.com/sassyn - yes, i said gcc-9 , gcc-8 has -lstdc++-fs @kostja https://github.com/kostja - the sample above has iostream include. It's not iostream that's the problem is the std::filesystem::filesystem_error

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/scylladb/seastar/issues/648?email_source=notifications&email_token=AAD2RF2QMTQ32KBMRXQBXI3PY3JUNA5CNFSM4HSYT3F2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW53PAQ#issuecomment-498841474, or mute the thread https://github.com/notifications/unsubscribe-auth/AAD2RFZXMOI24UPABBHF3CTPY3JUNANCNFSM4HSYT3FQ .

-- Regards,

Sassy Natan 972-(0)54-2203702